Previous topic

solve

Next topic

sorti

This Page

sortΒΆ

sort performs a quick 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
5.3.2 The SORT_REVERT and SORT_CASE constant definition added.
5.0.0 New parameter options.

See also

sorti, reshape

id-341140