Sort elements of symbolic arrays
sorts
the elements of Y
= sort(X
)X
in ascending lexicographical order.
If X
is a vector, then sort(X)
sorts the vector elements of X
.
If X
is a matrix, then sort(X)
treats the columns of X
as vectors and sorts each
column independently.
If X
is a multidimensional array, then
sort(X)
operates along the first array dimension
whose size does not equal 1, treating the elements as vectors.
[
also returns a collection of index vectors for any of the previous syntaxes.
Y
,I
] =
sort(___)I
is the same size as X
and describes the
arrangement of the elements of X
into Y
along
the sorted dimension. For example, if X
is an
m
-by-n
matrix and you sort the elements of
each column (dim = 1
), then each column of I
is an index vector of the sorted column of X
, such that
for j = 1:n Y(:,j) = X(I(:,j),j); end
Calling sort
for arrays of numbers that are not symbolic
objects invokes the MATLAB®
sort
function.
The sort
function sorts symbolic complex numbers
differently from MATLAB floating-point complex numbers. For symbolic input
X
that contains complex numbers,
sort(X)
sorts the complex numbers first by their real
parts, then by their imaginary parts to break ties. For floating-point input
X
, by default, sort(X)
sorts complex
numbers by their magnitude, followed by their phase angles in the interval (−π,
π] to break ties.