Azzera filtri
Azzera filtri

rank the columns by the means of nonzero values

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

Chad Greene
Chad Greene il 6 Feb 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);

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by