Clear Filters
Clear Filters

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

2 views (last 30 days)
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.

Accepted Answer

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

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!