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

2 次查看(过去 30 天)
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.

采纳的回答

Jan
Jan 2016-1-6
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 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by