Borrar filtros
Borrar filtros

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

3 visualizaciones (últimos 30 días)
alexaa1989
alexaa1989 el 22 de En. de 2015
Editada: Guillaume el 22 de En. de 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

Respuesta aceptada

Guillaume
Guillaume el 22 de En. de 2015
Editada: Guillaume el 22 de En. de 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.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by