Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
根据另一个矩阵重新排列矩阵行-MATLAB_Matlab_Membership - Fatal编程技术网

根据另一个矩阵重新排列矩阵行-MATLAB

根据另一个矩阵重新排列矩阵行-MATLAB,matlab,membership,Matlab,Membership,我有两个具有相同ID的矩阵mat1每个ID有多行,而mat2每个ID只有1行。矩阵是预先排序的 % COL1 -> ID mat1 = [ 20 2008 0.11 ; 20 2010 0.22 ; 30 2001 0.99 ; 40 2011 0.11 ; 40 2011 0.22 ; 40 2012 0.11 ] ; mat2 = [ 20 0.88 ; 30 0.11 ; 40 0.99 ] ; 需要根据mat1中对应的行数重复mat2 ID mat2 = [ 20 0.88

我有两个具有相同ID的矩阵
mat1
每个ID有多行,而
mat2
每个ID只有1行。矩阵是预先排序的

% COL1 -> ID
mat1 = [ 20 2008 0.11 ; 20 2010 0.22  ; 30 2001 0.99 ; 40 2011 0.11 ; 40 2011 0.22 ; 40 2012 0.11 ] ; 
mat2 = [ 20 0.88 ; 30 0.11 ; 40 0.99 ] ;
需要根据mat1中对应的行数重复mat2 ID

mat2 = [ 20 0.88 ; 20 0.88 ; 30 0.11 ; 40 0.99 ; 40 0.99 ; 40 0.99 ] ;
你能提出一个答案吗?就我个人而言,我想使用
ackmaray
等来获取每个ID的行数,然后可能是repmat mat2。谢谢。

试试这个:

[b,m,n] = unique(mat1(:,1));
mat3 = mat2(n,:)

希望这有助于……

谢谢!直截了当的为什么我会想到accumarray!