필터 지우기
필터 지우기

rank the columns by the means of nonzero values

조회 수: 1 (최근 30일)
Qian cao
Qian cao 2016년 2월 6일
답변: Chad Greene 2016년 2월 6일
Hi all, how can I rank the following matrix A by the rules as following described steps: 1.calculate the mean vector of the nonzero values in each column. * _ mean=[3 3 5 4 1.5]_* (I don't know how to calculate the average with a denominator equal to the number of nonzero values) 2. Rank the matrix A according to the mean values. So the column that has the calculated smallest mean comes first and then the column with a mean of 3 ...
A=
0 4 12 5 1
2 0 1 7 0
0 2 0 1 0
0 0 0 3 2
4 3 2 4 0
The expected matrix B after ranking is B=
1 0 4 5 12
0 2 0 7 1
0 0 2 1 0
2 0 0 3 0
0 4 3 4 2

채택된 답변

Chad Greene
Chad Greene 2016년 2월 6일
Use the mean function and specify the dimension along which you want to calculate the means. Then use sort in the syntax
[~,ind] = sort(A_means);
to get the indices of the sorted A_means vector. Reorder A by
B = A(:,ind);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by