FUNCTION REFERENCE
sort
Sort array elements.
Sort array elements.
Syntax
B = sort(A)Syntax
B = sort(A, dim)Syntax
B = sort(A, dim, 'descend')Syntax
[B, I] = sort(A, ..., 'MissingPlacement', value)Sorts each column of A in ascending order, or along dimension dim.
I holds the original positions, so B equals A(I) for a vector.
Equal values keep their original order. NaN values go last when ascending.
Example
[B, I] = sort([3 1 2]) % B = [1 2 3], I = [2 3 1]Example
sort(reshape([3 1 2 4],1,2,2),3,'descend')Differences from MATLAB: Real, logical, complex, character and cellstr 2-D arrays are supported. Complex values order by abs, then angle in (-pi, pi], NaN last, stable in both directions; complex input accepts dim and 'ascend'/'descend' only. Cellstr input accepts no sorting options. N-D arrays (part 2): [B,I] = sort(A,dim,'ascend'|'descend') along any dimension for numeric, logical, char and complex input.
These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.