array sorting 2D

조회 수: 15 (최근 30일)
jesus escareno
jesus escareno 2017년 3월 14일
댓글: jesus escareno 2017년 3월 14일
Lets say I had a matrix A
A = [ 5,2,3,6,8;
3,9,5,7,2;
4,3,2,1,11]
so that when i sorted the matrix then becomes
A = [1,2,3,4,11;
2,3,5,6,8;
2,3,5,7,9;]
  댓글 수: 1
Walter Roberson
Walter Roberson 2017년 3월 14일
Almost everything makes sense in the answer, but why is 11 in the top row instead of the bottom row?

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

채택된 답변

Roger Stafford
Roger Stafford 2017년 3월 14일
A = sortrows(sort(A,2));
  댓글 수: 2
Walter Roberson
Walter Roberson 2017년 3월 14일
Ah!
jesus escareno
jesus escareno 2017년 3월 14일
Thank You. I was trying doing a double sort but that didnt work. This worked perfectly.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2017년 3월 14일
I suspect you want
A = reshape( sort(A(:)), size(A) );

카테고리

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