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 sort3 Search Tools-> contents reference index search

Sorting Rows With a Specified Key
 Syntax `sort(`matrix`, `start`, `width`)` See Also reverse , sort(matrix) , and psort(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 order of the rows is determined by the values in the field beginning at column start and width columns wide, where start and width are integer scalars.

Example
To sort the matrix ```      / 1  3 \      | 2  4 |      \ 3  2 / ```by the second column, enter ```      y = {[1, 3], [2, 4], [3, 2]}      sort(y, 2, 1) ``` O-Matrix will respond ```      {      [ 3 , 2 ]      [ 1 , 3 ]      [ 2 , 4 ]      } ``` The `sort` function can also be used with character matrices. ```      x = {"Mary Frye", "Joe Friday", "Jack Frost"}      y = align(x, " ", [8, 8])      sort(y, 9, 8) ``` returns ```      Joe     Friday      Jack    Frost      Mary    Frye ```