필터 지우기
필터 지우기

How to find the rank of an array among all arrays?

조회 수: 3 (최근 30일)
alexaa1989
alexaa1989 2015년 1월 22일
편집: Guillaume 2015년 1월 22일
Hi everyone.
I need to find the rank of an array among all arrays in a matrix. For example if we have this matrix [0.6 0.27 0.03 0.5], since number 0.03 is the smallest it has the rank of 1 and since 0.27 is second it has the rank of two and a matrix as follows is resulted [4 2 1 3].
Can anyone tell me how to write its code? I already used Sort but didn't work. thank you all in advance

채택된 답변

Guillaume
Guillaume 2015년 1월 22일
편집: Guillaume 2015년 1월 22일
'It didn't work' is not a particularly helpful comment, rather you need to tell us what error you got, and why you think it didn't work:
sort is indeed the function you need, in particular the 2nd return value. You just then need to reorder the indices of the matrix according to that second value:
m = [0.6 0.27 0.03 0.5];
[~, order] = sort(m);
rank(order) = 1:numel(m)
Note that you don't have arrays in a matrix, but number. An array is the same as a matrix.

추가 답변 (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