sortiΒΆ
sorti sorts a real, complex or string matrix or vector in ascending order and returns an index vector of the sorted matrix.
-
rvSortIndex = sorti(mUnsorted)
-
rvSortIndex = sorti(mUnsorted, options)
Return Value
rvSortIndex is a index vector of the sorted matrix.
Parameters
-
mUnsorted
mUnsorted is the unsorted matrix. The first column will be sorted.
-
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: sorti 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
* sorti(a) // sort first column
2.0000
3.0000
1.0000
* // sort second column
* sorti(a[;2])
3.0000
1.0000
2.0000
* // sort third column
* a = a[sorti(a[;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.0.0 | New parameter options. |
id-1715870