Azzera filtri
Azzera filtri

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

3 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Guillaume
Guillaume il 22 Gen 2015
Modificato: Guillaume il 22 Gen 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.

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by