Note: This page has been translated by MathWorks. Please click here

To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.

To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.

Sort array elements

`B = sort(A)`

`B = sort(A,dim)`

`B = sort(___,direction)`

`B = sort(___,Name,Value)`

```
[B,I] =
sort(___)
```

sorts
the elements of `B`

= sort(`A`

)`A`

in ascending order.

If

`A`

is a vector, then`sort(A)`

sorts the vector elements.If

`A`

is a matrix, then`sort(A)`

treats the columns of`A`

as vectors and sorts each column.If

`A`

is a multidimensional array, then`sort(A)`

operates along the first array dimension whose size does not equal 1, treating the elements as vectors.

specifies
additional parameters for sorting. For example, `B`

= sort(___,`Name,Value`

)`sort(A,'ComparisonMethod','abs')`

sorts
the elements of `A`

by magnitude.

The

`sortrows`

function provides additional flexibility for subsorting over multiple columns of matrix or table inputs.The

`sort`

function and the relational operators use different orderings for complex numbers. For more information, see Relational Operations.

Was this topic helpful?