get the sub matrix composed of the three columns with the largest mean values
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi there, I get a matrix
d=
1 3 10 20 34
2 4 9 21 32
2 2 7 23 34
1 5 6 14 39
What I need to do is to first get the mean values of the columns, and then by ranking we get the index of the three columns with the largest means. Finally, we form a new matrix d_sub which is a sub matrix of d and is composed of the three columns. So the expected outcome of the d_sub is
dsub=
10 20 34
9 21 32
7 23 34
6 14 39
In the meantime , there is a matrix A which is 4*5 matrix, I need to get the sub matrix of A (namely A_sub) with three columns whose indexes are the same as those we have got from the last step. So the A_sub matrix is composed of the third, fourth and fifth columns of matrix A as well.
Thanks for your answers. br.
0 commentaires
Réponse acceptée
Jan
le 6 Jan 2016
d = [1 3 10 20 34; ...
2 4 9 21 32; ...
2 2 7 23 34; ...
1 5 6 14 39];
m = mean(d, 1); % The sum would be cheaper...
[dummy, index] = sort(m, 'descend');
wanted = index(1:3);
dsub = d(:, wanted);
A_sub = A(:, sub);
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!