.. highlightlang:: us .. index:: sort .. _sort: sort ==== .. us.tag sort ENGLISH STR math-base Changed500 Changed532 Changed5502 :ref:`sort` performs a sort from a real, complex or string matrix or vector. .. function:: mSorted = sort(mUnsorted) mSorted = sort(mUnsorted, options) .. us.return **Return Value** *mSorted* is the sorted matrix. .. us.params **Parameters** .. uparam:: 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. .. uparam:: options *options* is a OR combination of the following values: .. list-table:: :header-rows: 0 * - SORT_REVERT (1) - Sort in descending order. Default ascending order. * - SORT_CASE (2) - Case sensitive sorting (only for string vectors/matrices). Default: :ref:`sort` ignores case. .. us.example **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 .. us.history **History** .. list-table:: :header-rows: 1 * - 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 ``SORT_REVERT`` and ``SORT_CASE`` constant definition added. * - 5.0.0 - New parameter *options*. .. seealso:: :ref:`sorti`, :ref:`reshape` :sub:`id-341140`