フィルターのクリア

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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by