rank the columns by the means of nonzero values

1 visualización (últimos 30 días)
Qian cao
Qian cao el 6 de Feb. de 2016
Respondida: Chad Greene el 6 de Feb. de 2016
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

Respuesta aceptada

Chad Greene
Chad Greene el 6 de Feb. de 2016
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);

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by