Ranking of an array.

조회 수: 1 (최근 30일)
Abdullah Muratoglu
Abdullah Muratoglu 2011년 10월 9일
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
bym
bym 2011년 10월 9일
how does [1,5; 7 9; 2 0] produce [2 4; 5 6; 1 3]?
I don't understand what your goal is

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2011년 10월 9일
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
Andrei Bobrov
Andrei Bobrov 2011년 10월 10일
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 2011년 10월 10일
perfect!
Thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by