sortrows - Sort rows

Class

@ordinal

Syntax

B = sortrows(A)
B = sortrows(A,col)
[B,I] = sortrows(A)
[B,I] = sortrows(A,col)

Description

B = sortrows(A) sorts the rows of the two-dimensional ordinal matrix A in ascending order, as a group. B is an ordinal array with the same levels as A.

B = sortrows(A,col) sorts A based on the columns specified in the vector col. If an element of col is positive, the corresponding column in A is sorted in ascending order; if an element of col is negative, the corresponding column in A is sorted in descending order.

[B,I] = sortrows(A) and [B,I] = sortrows(A,col) also returns an index matrix I such that B = A(I,:).

Elements with undefined levels are sorted to the end.

Example

Sort the rows of an ordinal array in ascending order for the first column, and then in descending order for the second column:

A = ordinal([6 2 5; 2 4 1; 3 2 4],...
            {'lo','med','hi'},[],[0 2 4 6])
A = 
     hi       med      hi 
     med      hi       lo 
     med      med      hi 

B = sortrows(A,[1 -2])
B = 
     med      hi       lo 
     med      med      hi 
     hi       med      hi 

See Also

sort, sortrows

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS