|MATLAB Function Reference|
Sort rows in ascending order
B = sortrows(A)
sorts the rows of
A as a group in ascending order. Argument
A must be either a matrix or a column vector.
For strings, this is the familiar dictionary sort. When
A is complex, the elements are sorted by magnitude, and, where magnitudes are equal, further sorted by phase angle on the interval .
B = sortrows(A,column)
sorts the matrix based on the columns specified in the vector
column. For example,
sortrows(A,[2 3]) sorts the rows of
A by the second column, and where these are equal, further sorts by the third column.
[B,index] = sortrows(A)
also returns an index vector
A is a column vector, then
B = A(index).
A is an
n matrix, then
B = A(index,:).
Given the 5-by-5 string matrix,
The commands B = sortrows(A) and C = sortrows(A,1) yield