How to sort a matrix in desceding order?

조회 수: 1 (최근 30일)
SM
SM 2020년 2월 9일
댓글: SM 2020년 2월 9일
I have a matrix such as:
A =[
0.8604 0.5134 0.9391 0.6482 0.3479 0.3308 0.7069 0.7640 0.0567 0.9052
0.9344 0.1776 0.3013 0.0252 0.4460 0.8985 0.9995 0.8182 0.5219 0.6754
0.9844 0.3986 0.2955 0.8422 0.0542 0.1182 0.2878 0.1002 0.3358 0.4685
0.8589 0.1339 0.3329 0.5590 0.1771 0.9884 0.4145 0.1781 0.1757 0.9121
0.7856 0.0309 0.4671 0.8541 0.6628 0.5400 0.4648 0.3596 0.2089 0.1040];
if i use
[~, sortOrder] = sort(A(1,:), 'descend')
then it gives
sortOrder=[3 10 1 8 7 4 2 5 6 9];
but if i apply this code for all rows such as
[~, sortOrder] = sort(A(:), 'descend')
it shows results which i dont want.
How can i solve it if i want the following outcome:
sortOrder=
[3 10 1 8 7 4 2 5 6 9
7 1 6 8 10 9 5 3 2 4
1 4 10 2 9 3 7 6 8 5
6 10 1 4 7 3 8 5 9 2
4 1 5 6 3 7 8 9 10 2];
No for loop please! I use R2017b.
Thanks in advance!

채택된 답변

Walter Roberson
Walter Roberson 2020년 2월 9일
[~, sortOrder] = sort(A, 2, 'descend');
  댓글 수: 1
SM
SM 2020년 2월 9일
Thank you! it works for me.

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

추가 답변 (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