Contents Previous Next Subchapters Current Chapters-> align atod atoi char2dbl ntoa num2str str2num strreplace strclip clipstr low2up up2low dquote file2str pack unpack char2id reprow str2strdir sort sort3 psort psort3 mlmode_sort reverse flipud fliplr rot90 nonzeros find find2 find3 dec2hex hex2dec findstr whichrow Parent Chapters-> Omatrix6 stringssort mlmode_sort Search Tools-> contents reference index search

Sorting (Mlmode)
 Syntax y = sort(x) y = sort(x, d) [y, idx] = sort(x) [y, idx] = sort(x, d) See Also sort , reverse

Description
Sorts the elements of the matrix x where x is a character, integer, real, or double-precision matrix. (See sort for sorting rows of a matrix.) The return value y has the same type and dimension as x.

Direction of Sort
The argument d is an integer, real or double-precision scalar equal to one or two. The value one corresponds to sorting each column and two corresponding to sorting each row. If d is not present and the row dimension of x is not equal to one, the columns of x are sorted (same as d = 1 case). If d is not present and the row dimension of x is equal to one, the row vector x is sorted (same as d = 2 case).

Index of Sort
The return value idx in an integer matrix with the same dimension as x. In the d = 1 case,
y      = x
i,j      idx(i,j) , j
In the d = 2 case,
y      = x
i,j      iidx(i,j)

Example
If in Mlmode you enter
x = [ 3 2 1 0 ]
[y, idx] = sort(x)
y