Contents Previous Next Subchapters

Sorting Rows With a Specified Key
Syntax sort(matrixstartwidth)
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