0

Possible Duplicate:
How can I sort a 2-D array in MATLAB with respect to one column?

I want to sort one column of a 2D matrix and still retain the relative row-position of an element in that column to other elements of the same row. So if the 3rd element of this column is to be swapped with the 1st element, then swap row 3 with row1, etc. How can I do this in Matlab? Thank you.

Community
  • 1
  • 1
Martin08
  • 20,990
  • 22
  • 84
  • 93
  • Duplicate: [How can I sort a 2-D array in MATLAB with respect to one column?](http://stackoverflow.com/questions/134712/how-can-i-sort-a-2-d-array-in-matlab-with-respect-to-one-column) – gnovice Apr 08 '11 at 20:43

1 Answers1

0

This does the trick:

B = sortrows(A, column_number);
AVH
  • 11,349
  • 4
  • 34
  • 43