rank the columns by the means of nonzero values
1 次查看(过去 30 天)
显示 更早的评论
Hi all, how can I rank the following matrix A by the rules as following described steps: 1.calculate the mean vector of the nonzero values in each column. * _ mean=[3 3 5 4 1.5]_* (I don't know how to calculate the average with a denominator equal to the number of nonzero values) 2. Rank the matrix A according to the mean values. So the column that has the calculated smallest mean comes first and then the column with a mean of 3 ...
A=
0 4 12 5 1
2 0 1 7 0
0 2 0 1 0
0 0 0 3 2
4 3 2 4 0
The expected matrix B after ranking is B=
1 0 4 5 12
0 2 0 7 1
0 0 2 1 0
2 0 0 3 0
0 4 3 4 2
0 个评论
采纳的回答
Chad Greene
2016-2-6
Use the mean function and specify the dimension along which you want to calculate the means. Then use sort in the syntax
[~,ind] = sort(A_means);
to get the indices of the sorted A_means vector. Reorder A by
B = A(:,ind);
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!