sortΒΆ
sort performs a sort from a real, complex or string matrix or vector.
- mSorted = sort(mUnsorted)
- mSorted = sort(mUnsorted, options)
Return Value
mSorted is the sorted matrix.
Parameters
- mUnsorted
mUnsorted is the unsorted matrix. The first column will be sorted and the other columns will be changed accordingly to match the first column.
- options
options is a OR combination of the following values:
SORT_REVERT (1)
Sort in descending order. Default ascending order.
SORT_CASE (2)
Case sensitive sorting (only for string vectors/matrices). Default: sort ignores case.
Example
* srand("test")
1.0000
* a = rand(3,3)
* a
0.5536 0.7214 0.6267
0.0735 0.9892 0.8892
0.4024 0.0891 0.5894
* sort(a) // sort 1 column
0.0735 0.9892 0.8892
0.4024 0.0891 0.5894
0.5536 0.7214 0.6267
* // sort 2 column
* a[;2,1,3] = sort(a[;2,1,3])
* a
0.4024 0.0891 0.5894
0.5536 0.7214 0.6267
0.0735 0.9892 0.8892
History
Version |
Description |
---|---|
R2013.2 |
Uses mergesort instead of quicksort. Mergesort is a stable sort, which means the implementation preserves the input order of equal elements in the sorted output. |
5.3.2 |
The |
5.0.0 |
New parameter options. |
id-341140