Products & Services Solutions Academia Support User Community Company

Learn more about Statistics Toolbox   

sortrows - Class: ordinal

Sort rows

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 2-D 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.

Examples

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

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

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