sort
Sort elements of symbolic arrays
Description
sorts
the elements of Y
= sort(X
)X
in the default ascending order.
If
X
is a vector, thensort(X)
sorts the vector elements ofX
.If
X
is a matrix, thensort(X)
treats the columns ofX
as vectors and sorts each column independently.If
X
is a multidimensional array, thensort(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
Examples
Input Arguments
Output Arguments
Tips
Calling
sort
on arrays of numbers that are not symbolic objects invokes the MATLAB®sort
function.