MATLAB Function Reference
  Go to function:
    Search    Help Desk 
sortrows    Examples   See Also

Sort rows in ascending order

Syntax

Description

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 index.

If A is a column vector, then B = A(index).

If A is an m-by-n matrix, then B = A(index,:).

Examples

Given the 5-by-5 string matrix,

The commands B = sortrows(A) and C = sortrows(A,1) yield

See Also

sort        Sort elements in ascending order



[ Previous | Help Desk | Next ]