B = sort(A)
B = sort(A, dim)
B = sort(..., direction)
B = sort(..., name, value)
B = sort(A, dim, direction, name, value)
[B, I] = sort(...)
| Parameter | Description |
|---|---|
| A | an nelson's variable (double, single, int8, int16, int32, int64, uint8, uint16, uint32, uint64, logical, char, string, cell). |
| dim | Dimension to operate along: positive integer scalar. |
| direction | Sorting direction: 'ascend' (default) or 'descend'. |
| name, value | name-value pair arguments. |
| Parameter | Description |
|---|---|
| B | sorted array. |
| I | sort index. |
sort implements quick sort algorithm.
With two outputs, elements with equivalent sort keys retain their original order. The indices returned for equivalent values are increasing within each group, in either sorting direction.
Name-value pairs can be used after the dimension and sorting direction.
name-value pair arguments:
'MissingPlacement' - Placement of missing values: 'auto' (default), 'first' , 'last' .
'ComparisonMethod' - Element comparison method: 'auto' (default), 'real' , 'abs' .
With 'MissingPlacement' set to 'last', nonmissing values are sorted in the requested direction and missing values follow them. This applies with one or two outputs. A missing string is distinct from an empty string.
Complex values with a NaN in either component are missing. They retain their input order with one or two outputs, including the non-NaN component, for every missing placement and sorting direction.
A = [10+20i 30+i 10i 0 -10i];
B = sort(A,'ComparisonMethod', 'auto')
B = sort(A, 'ComparisonMethod', 'real')
B = sort(A, 'ComparisonMethod', 'abs')
A = [NaN 3 6 0 NaN];
[B, I] = sort(A, 'MissingPlacement', 'auto')
[B, I] = sort(A, 'MissingPlacement', 'first')
[B, I] = sort(A, 'MissingPlacement', 'last')
| Version | Description |
|---|---|
| 1.0.0 | initial version |