Filter löschen
Filter löschen

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

3 Ansichten (letzte 30 Tage)
alexaa1989
alexaa1989 am 22 Jan. 2015
Bearbeitet: Guillaume am 22 Jan. 2015
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

Akzeptierte Antwort

Guillaume
Guillaume am 22 Jan. 2015
Bearbeitet: Guillaume am 22 Jan. 2015
'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.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by