SORT command
| Syntax: | SORT x { x1 x2 ... } |
| Qualifiers: | \UP, \DOWN |
| Defaults: | \UP |
The SORT command sorts vectors into
ascending or descending order. By default, the vector
x is sorted into ascending order.
Ascending order means that element 1 will be the smallest
element. To sort vector x into
descending order, use the \DOWN
qualifier. Descending order means that element 1 will
be the largest. Vector x will be
altered. If other vectors, xI, are
entered, then they will not be sorted, but they will be re-arranged in
the same way that x is re-arranged.
For example, if element x[i] becomes
x[j] because of sorting, then xI[i] will become xI[j].
Example 1
Suppose you have a data vector, X = [1;2;3;4;5]
To sort X into descending order, enter:
SORT\DOWN X
after which X = [5;4;3;2;1]
Example 2
Suppose you have three data vectors, X, Y, and
Z, which represent rectangular coordinates and an associated
altitude:
X = [1;2;3;4;5],
Y = [10;8;6;4;2],
Z = [-.3;-1;-.5;2;-2]
If you want to sort Z into descending order, without breaking
up the triplets, enter:
SORT\DOWN Z X Y
After which the vectors are:
X = [4;1;3;2;5],
Y = [4;10;6;8;2],
Z = [2;-.3;-.5;-1;-2]
Example 3
Suppose you have three data vectors, X, Y, and
Z, which represent rectangular coordinates and an associated
altitude:
X = [1;2;3;4;5],
Y = [10;8;6;4;2],
Z = [-.3;-1;-.5;2;-2]
If you want to sort Y into ascending order, without breaking up
the triplets, enter:
SORT\DOWN Y X Z
After which the vectors are:
X = [5;4;3;2;1],
Y = [2;4;6;8;10],
Z = [-2;2;-.5;-1;-.3]