Can anyone help : rank each row of a matrix

조회 수: 3 (최근 30일)
Qian cao
Qian cao 2016년 2월 5일
댓글: Jan 2016년 2월 14일
Hi all, If I have a matrix like
A=
0.2 NaN 0.8 0.8
-0.2 1 0.3 0.2
0.2 -0.3 0.2 2
0.7 -0.1 -0.4 0.7
NaN 0.2 NaN 0.9
How do I get a resulting matrix B which ranks each row of A and the result shows like this ... Please Pay attention to row 3. I am looking for a complete answer for this as I am new in Matlab. Thank you a lot !
B=
1 NaN 2 2
1 4 3 2
2 1 2 4
3 2 1 3
NaN 1 NaN 2
  댓글 수: 2
Jan
Jan 2016년 2월 5일
You forgot to mention the definition of "ranking". There is an infinite number of possible methods to obtain B based on A.
Stephen23
Stephen23 2016년 2월 5일
Do not post duplicate questions:
You can simply add a comment to your original question.

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

답변 (1개)

Jan
Jan 2016년 2월 5일
편집: Jan 2016년 2월 14일
A guess:
A = [0.2 NaN 0.8 0.8; ...
-0.2 1 0.3 0.2; ...
0.2 -0.3 0.2 2; ...
0.7 -0.1 -0.4 0.7; ...
NaN 0.2 NaN 0.9];
B = nan(size(A));
for k = 1:size(A, 1)
valid = isfinite(A(k, :));
Ak = A(k, valid);
[~, ~, iC] = unique(Ak, 'sorted'); % [EDITED, 3rd instead of 2nd output]
B(k, valid) = Ak(iC);
end
  댓글 수: 3
Jan
Jan 2016년 2월 9일
편집: Jan 2016년 2월 9일
@Qian cao: Please explain this with any details. Do you get an error message? Are you able to idenitfy the error and fix it by your own?
Did you see, that I asked you for a definition of "ranking"? So please give us a chance to answer efficiently without guessing, what you want and observe.
Jan
Jan 2016년 2월 14일
@Qian cao: What a pitty that you do not answer my question for clarification. Nevertheless, I've edited my answer. Perhaps it is "working" now.

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

카테고리

Help CenterFile Exchange에서 Particle & Nuclear Physics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by