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

采纳的回答

Chad Greene
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 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by