Return a copy of x with the elements arranged in increasing order. For matrices,
sortorders the elements in each column.For example,
sort ([1, 2; 2, 3; 3, 1]) 1 1 2 2 3 3The
sortfunction 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 2If the optional argument dim is given, then the matrix is sorted along the dimension defined by dim. The optional argument
modedefines the order in which the values will be sorted. Valid values ofmodeare `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
sortfunction 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
sortis optimized for the sorting of partially ordered lists.