Group: | Matrix Manipulation |
Topic: | Sorting and Counting |
See also: | index |
Function: | sort | |
Description: | sort sorts the rows of a matrix. If column c1 is specified the matrix will be sorted with respect to column c1. That is, the rows of the matrix will be arranged in order that elements of column c1 are in ascending (descending) order. |
Usage: | z = sort (x, c) | |
Input: | ||
x | n x p x d1 x ...x dn array | |
c | m x 1 vector | |
Output: | ||
z | n x p x d1 x ...x dn array |
If c[j] (j=1...m) is positive the sort will be in ascending order. to sort in descending order with respect to c[j] input as parameter -c[j].
To sort every column of matrix x separately use z=sort(x, 0).
x = #(3, 1, 1, 3, 1)~#(4, 5, 4, 2, 4)~#(1, 5, 4, 0, 1) sort(x', #(-1, 2))
Contents of sort [1,] 4 5 4 2 4 [2,] 3 1 1 3 1 [3,] 1 5 4 0 1