FUNCTION REFERENCE

sortrows

Sort rows of a matrix.

Sort rows of a matrix.

Syntax

B = sortrows(A)

Syntax

[B, I] = sortrows(A, cols, 'descend', 'MissingPlacement', 'last')

cols is a vector of signed column numbers; a negative number sorts that column in descending order. 'ascend' or 'descend' applies to all columns. NaN placement is auto, first or last.

Example

sortrows([3 1; 1 2; 2 0])   % [1 2; 2 0; 3 1]

Differences from MATLAB: Real, logical, character and cellstr 2-D arrays and tables are supported (see help table for sortrows(T, vars, direction)). No per-column direction arrays for arrays. Cellstr input accepts numeric column selectors, including negative columns, but no text options. Complex input sorts by abs, then angle, with numeric column selectors only.

These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.