2014-02-27 84 views
0

给定矩阵A m x n我想重新组织其行,以便从行1n行上的平均值增加。根据其行的平均值重新排列矩阵

有没有简单的方法呢?

E.g.输入输出A = [5 5 5; 3 3 3; 2 2 2; 4 4 4]B = [2 2 2; 3 3 3; 4 4 4; 5 5 5]

回答

2

我想你的意思,不;和意味着,不位数

[~, ind] = sort(mean(A.')); %'// get indices of sorting the row means 
B = A(ind,:); %// apply that sorting to the matrix 

(你可以使用sum代替mean节省一些时间)。

如果你真的是

[~, ind] = sort(mean(A)); 
B = A(:,ind); 

如果你真的是平均,通过median更换mean