Return a copy of x with the elements arranged in increasing
order. For matrices, sort
orders the elements in each column.
For example:
sort ([1, 2; 2, 3; 3, 1]) ⇒ 1 1 2 2 3 3
The sort
function may also be used to produce a matrix
containing the original row indices of the elements in the sorted
matrix. For example:
[s, i] = sort ([1, 2; 2, 3; 3, 1]) ⇒ s = 1 1 2 2 3 3 ⇒ i = 1 3 2 1 3 2
If the optional argument dim is given, then the matrix is sorted
along the dimension defined by dim. The optional argument mode
defines the order in which the values will be sorted. Valid values of
mode
are ‘ascend’ or ‘descend’.
For equal elements, the indices are such that the equal elements are listed in the order that appeared in the original list.
The sort
function may also be used to sort strings and cell arrays
of strings, in which case the dictionary order of the strings is used.
The algorithm used in sort
is optimized for the sorting of partially
ordered lists.
Package: dataframe