MATLAB: Ranking of an array.

ranksort

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

Best Answer

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));