matlab

How to sort a matrix by using values in another vector in matlab?

浪子不回头ぞ 提交于 2021-02-11 05:12:33
问题 My situation is: I get a 1000*2 matrix and a 1000*1 vector. And the row i in the matrix is mapped to the element i in the vector. And the elements in the vector are all integer. Now I want to sort the elements in the vector from low to high. And I want to get a new matrix with the sequence of the new vector. And the mapping relationships are equal to the original situation. How to do this in Matlab? Thanks! 回答1: Use sortrows: First concat your vector to your matrix: M2 = [V, M]; Then sort

How to sort a matrix by using values in another vector in matlab?

十年热恋 提交于 2021-02-11 05:10:04
问题 My situation is: I get a 1000*2 matrix and a 1000*1 vector. And the row i in the matrix is mapped to the element i in the vector. And the elements in the vector are all integer. Now I want to sort the elements in the vector from low to high. And I want to get a new matrix with the sequence of the new vector. And the mapping relationships are equal to the original situation. How to do this in Matlab? Thanks! 回答1: Use sortrows: First concat your vector to your matrix: M2 = [V, M]; Then sort

How to sort a matrix by using values in another vector in matlab?

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-11 05:09:49
问题 My situation is: I get a 1000*2 matrix and a 1000*1 vector. And the row i in the matrix is mapped to the element i in the vector. And the elements in the vector are all integer. Now I want to sort the elements in the vector from low to high. And I want to get a new matrix with the sequence of the new vector. And the mapping relationships are equal to the original situation. How to do this in Matlab? Thanks! 回答1: Use sortrows: First concat your vector to your matrix: M2 = [V, M]; Then sort

Named Pipes Matlab

只谈情不闲聊 提交于 2021-02-11 01:45:39
问题 I am having trouble locating an example for creating a windows named pipe in matlab. Any suggestions on how to program or where to look? 回答1: Using .NET's System.IO.Pipes is probably the easiest way out of the box, easier than writing a MEX file to call the Win32 API. Matlab lets you call .NET directly from M-code, and the objects are managed so resource cleanup will be easier. .NET 3.5 and newer support named pipes. The resulting M-code would look something like this. (Sorry; I don't have

Named Pipes Matlab

我怕爱的太早我们不能终老 提交于 2021-02-11 01:44:31
问题 I am having trouble locating an example for creating a windows named pipe in matlab. Any suggestions on how to program or where to look? 回答1: Using .NET's System.IO.Pipes is probably the easiest way out of the box, easier than writing a MEX file to call the Win32 API. Matlab lets you call .NET directly from M-code, and the objects are managed so resource cleanup will be easier. .NET 3.5 and newer support named pipes. The resulting M-code would look something like this. (Sorry; I don't have

MATLAB之矩阵

混江龙づ霸主 提交于 2021-02-11 00:11:12
一、A为3行4列的矩阵,B为一个行数大于3的矩阵,写出MATLAB命令。 (1)删除A的第1、3两列。 (2)删除B的倒数第3行。 (1)删除A的第1、3列 ​A=rand(3,4) ​A(:,[1,3])=[] 输出: A = 0.9572 0.1419 0.7922 0.0357 0.4854 0.4218 0.9595 0.8491 0.8003 0.9157 0.6557 0.9340 A = 0.1419 0.0357 0.4218 0.8491 0.9157 0.9340 (2)删除B的倒数第三行 K=fix(rand(1,10)*10)%%生成随机数 for i=1:10 ​if K(i)>3 ​k=K(i); ​break; ​end end B=rand(k) B(k-2,:)=[]%%删除B的倒数第三行 输出 K = 4 6 6 6 0 0 3 5 6 4 B = 0.8200 0.3251 0.4235 0.2810 0.7184 0.1056 0.0908 0.4401 0.9686 0.6110 0.2665 0.5271 0.5313 0.7788 0.1537 0.4574 B = 0.8200 0.3251 0.4235 0.2810 0.9686 0.6110 0.2665 0.5271 0.5313 0.7788 0.1537 0.4574 二

matlab矩阵的操作

南楼画角 提交于 2021-02-10 20:52:56
特殊矩阵 通用型的特殊矩阵 zeros函数:产生全0矩阵,即零矩阵 ones函数:产生全1矩阵,即幺矩阵 eye函数: 产生对角线为1的矩阵。当矩阵是方阵时,得到一个单位矩阵。 rand函数:产生(0,1)区间均匀分布的随机矩阵 randn函数:产生均值为0,方差为1的标准正态分布随机矩阵。 以上函数三种调用格式 例: 产生m x m 零矩阵 :zeros(m) 产生m x n 零矩阵 :zeros(m,n) 产生与矩阵A同型的零矩阵 :zeros(sizeof(A)) 面向专门学科的特殊矩阵 1、 魔方矩阵:n阶魔方阵由1..n 2 共n 2 个整数组成,其每行每列及主、副对角线元素 之和都相等。当n>=2时,有多个不同的n阶魔方阵。 magic(n):产生一个特定(不是所有的)n阶的魔方阵 2、 范德蒙(Vandermonde的)矩阵(常用与通信编码纠错): vander(v)函数:生成以向量V为基础的范德蒙矩阵 3、 希尔伯特(Hilbert)矩阵:H( i , j )= 1/ (i+j-) Hilb(n)函数:生成n阶希尔伯特矩阵 4、 伴随矩阵(??): Compan(p)函数:求矩阵P的伴随矩阵 5、 帕斯卡矩阵:P( i , j )=p(i , j-1) + p(i-1,j) 且 p(i , 1)= p(1,j)=1 Pascal(n)函数:生成帕斯卡矩阵 矩阵变换

Load an do operations with a matrix whose name varies within a Matlab loop

时光总嘲笑我的痴心妄想 提交于 2021-02-10 20:51:28
问题 I have to run a Matlab loop indexed by x . At each iteration, I have to load and work with an array, A_x.mat , where the subscript x follows the loop index. How can I do that? Let me give you and example to highlight my issue. The example is very silly but serves my purposes. X=10; C=cell(X,1) for x=1:X load(['A_' num2str(x) '.mat']); %here I load A_x.mat %C{x}=A_x*3; end I don't know how to compute A_x*3 in a way that allows the subscript x to vary. Could you advise? To solve my issue I also

Load an do operations with a matrix whose name varies within a Matlab loop

╄→尐↘猪︶ㄣ 提交于 2021-02-10 20:50:13
问题 I have to run a Matlab loop indexed by x . At each iteration, I have to load and work with an array, A_x.mat , where the subscript x follows the loop index. How can I do that? Let me give you and example to highlight my issue. The example is very silly but serves my purposes. X=10; C=cell(X,1) for x=1:X load(['A_' num2str(x) '.mat']); %here I load A_x.mat %C{x}=A_x*3; end I don't know how to compute A_x*3 in a way that allows the subscript x to vary. Could you advise? To solve my issue I also

Update matrix, single column per row where row index is in vecor

拟墨画扇 提交于 2021-02-10 19:40:28
问题 Is there a way to update different column in each row of matrix, where row indices are stored in vector. Example mx = zeros(10,10); cols = [2 3 5 4 6 8 9 1 2 3]'; for i = 1:size(mx,1) mx(i,cols(i)) = 1; end mx produces 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 The question is, whether I can do it without the for loop? 回答1: You can