get the sub matrix composed of the three columns with the largest mean values

1 Ansicht (letzte 30 Tage)
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.

Akzeptierte Antwort

Jan
Jan am 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);

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by