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

조회 수: 1 (최근 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에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by