5

I am looking to do a nested sort with a matrix in MATLAB. Say my matrix looks like this:

[b a; 
 b c;
 a c;
 a a]

I would like to first sort by the first column and maintain that sort, then sort by the second column. The result would be:

[a a;
 a c;
 b a;
 b c]

How would it be done?

Jacob
  • 34,255
  • 14
  • 110
  • 165
  • Duplicate: http://stackoverflow.com/questions/134712/sorting-2-d-array-in-matlab-w-r-t-one-column – gnovice Mar 25 '10 at 04:04

1 Answers1

13

sortrows would do the trick.

To be more detailed, sortrows(A,[1 2]), where A is your matrix.

Jacob
  • 34,255
  • 14
  • 110
  • 165
  • 1
    Thank you very much. That usage is not in the doc. Pretty intuitive when I think about it. –  Aug 12 '09 at 14:41