MATLAB Function Reference | Search  Help Desk |
sort | See Also |
Sort elements in ascending order
B = sort(A) [B,INDEX] = sort(A) B = sort(A,dim)
B = sort(A)
sorts the elements along different dimensions of an array, and arranges those elements in ascending order. a
can be a cell array of strings.
Real, complex, and string elements are permitted. For identical values in A
, the location in the input array determines location in the sorted list. When A
is complex, the elements are sorted by magnitude, and where magnitudes are equal, further sorted by phase angle on the interval . If A
includes any NaN
elements, sort
places these at the end.
If A
is a vector, sort(A)
arranges those elements in ascending order.
If A
is a matrix, sort(A)
treats the columns of A
as vectors, returning sorted columns.
If A
is a multidimensional array, sort(A)
treats the values along the first non-singleton dimension as vectors, returning an array of sorted vectors.
[B,INDEX] = sort(A)
also returns an array of indices. INDEX
is an array of size(A)
, each column of which is a permutation vector of the corresponding column of A
. If A
has repeated elements of equal value, indices are returned that preserve the original relative ordering.
B = sort(A,dim)
sorts the elements along the dimension of A
specified by scalar dim
.
If dim
is a vector, sort
works iteratively on the specified dimensions. Thus, sort(A,[1 2])
is equivalent to sort(sort(A,2),1)
.
max
Maximum elements of an array
mean
Average or mean value of arrays
median
Median value of arrays
min
Minimum elements of an array
sortrows
Sort rows in ascending order