Contents Previous Next Subchapters Current Chapters-> align atod atoi char2dbl ntoa num2str str2num strreplace strclip clipstr low2up up2low dquote file2str pack unpack char2id reprow str2strdir sort sort3 psort psort3 mlmode_sort reverse flipud fliplr rot90 nonzeros find find2 find3 dec2hex hex2dec findstr whichrow Parent Chapters-> Omatrix6 stringssort sort Search Tools-> contents reference index search

Sorting Rows Of A Matrix
 Syntax `sort(`matrix`)` See Also psort , mlsort , reverse sort(matrix, start, width)

Description
Returns a copy of matrix with its rows in ascending order, where matrix is a character, integer, real, or double-precision matrix. The first element that is not equal between two rows determines which row comes first. The argument matrix cannot be an empty matrix .

Example
The `sort` function can be used to sort the elements of a column vector. If you enter ```      x = {1, 3, 2}      sort(x) ``` O-Matrix will respond ```      {      1      2      3      } ``` The `sort` function can also be used to sort the rows of a matrix. If you enter ```      x = {[2, 1], [1, 2], [1, 1]}      sort(x) ``` O-Matrix will respond ```      {      [ 1 , 1 ]      [ 1 , 2 ]      [ 2 , 1 ]      } ``` Note that when two rows have equal first elements, the second element of each row determines which row is greater. If the second elements are equal, the `sort` function then looks at the third element, and so on. ``` ```To sort in descending order, use the reverse function.