array sorting 2D

13 Ansichten (letzte 30 Tage)
jesus escareno
jesus escareno am 14 Mär. 2017
Kommentiert: jesus escareno am 14 Mär. 2017
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 Kommentar
Walter Roberson
Walter Roberson am 14 Mär. 2017
Almost everything makes sense in the answer, but why is 11 in the top row instead of the bottom row?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Roger Stafford
Roger Stafford am 14 Mär. 2017
A = sortrows(sort(A,2));
  2 Kommentare
Walter Roberson
Walter Roberson am 14 Mär. 2017
Ah!
jesus escareno
jesus escareno am 14 Mär. 2017
Thank You. I was trying doing a double sort but that didnt work. This worked perfectly.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 14 Mär. 2017
I suspect you want
A = reshape( sort(A(:)), size(A) );

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by