Ranking of an array.

Hi, How can I do array rank of a matrix. Such that: [1,5; 7 9; 2 0] will produce [2 4; 5 6; 1 3]. I mean, all variables should be /ranked in an increment order. Lowest will be 1, the highest will be n

1 comentario

bym
bym el 9 de Oct. de 2011
how does [1,5; 7 9; 2 0] produce [2 4; 5 6; 1 3]?
I don't understand what your goal is

Iniciar sesión para comentar.

 Respuesta aceptada

Jan
Jan el 9 de Oct. de 2011

0 votos

I assume, the result should be [2 4; 5 6; 3 1] with the last two elements swapped. The method is called sorting, not ranking.
M = [1,5; 7 9; 2 0];
[dummy, index] = sort(M(:));
R(index) = 1:numel(M);
R = reshape(R, size(M));

4 comentarios

Abdullah Muratoglu
Abdullah Muratoglu el 9 de Oct. de 2011
Absolutely correct.
Thanks
Abdullah Muratoglu
Abdullah Muratoglu el 10 de Oct. de 2011
I realized, this code gives the same numbers, different ranks/sorts.
E.g: [3 3] will be ranked as [1 2] not [1 1]. How can I overcome this?
Andrei Bobrov
Andrei Bobrov el 10 de Oct. de 2011
A = [6 7
7 3
4 1]
[a, ignore, c] = unique(A);
B = A;
a1 = 1:numel(a);
B(:) = a1(c)
Abdullah Muratoglu
Abdullah Muratoglu el 10 de Oct. de 2011
perfect!
Thanks

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by