Contents Previous Next Subchapters

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

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 .

The sort function can be used to sort the elements of a column vector. If you enter
     x = {1, 3, 2}
O-Matrix will respond
The sort function can also be used to sort the rows of a matrix. If you enter
     x = {[2, 1], [1, 2], [1, 1]}
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.