Contents Previous Next Subchapters

Sorting (Mlmode)
Syntax y = sort(x)
y = sort(xd)
[yidx] = sort(x)
[yidx] = sort(xd)
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
O-Matrix will reply
     [ 0 1 2 3 ]
If you continue by entering
     idx
O-Matrix will reply
     [ 4 3 2 1 ]