Main Content

Determine if array is sorted

`TF = issorted(`

returns
the logical scalar 1 (`A`

)`true`

) when the elements of `A`

are
listed in ascending order and 0 (`false`

) otherwise.

If

`A`

is a vector, then`issorted`

returns 1 when the vector elements are in ascending order.If

`A`

is a matrix, then`issorted`

returns 1 when each column of`A`

is in ascending order.If

`A`

is a multidimensional array, then`issorted`

returns 1 when`A`

is in ascending order along the first dimension whose size does not equal 1.If

`A`

is a timetable, then`issorted`

returns 1 when its row time vector is in ascending order. To check the ordering of row times or variables of a timetable with additional options, use the`issortedrows`

function.

`TF = issorted(___,`

returns
1 when `direction`

)`A`

is sorted in the order specified by `direction`

for
any of the previous syntaxes. For example, `issorted(A,'monotonic')`

returns
1 if the elements of `A`

are ascending or descending.

`TF = issorted(___,`

specifies
additional parameters for checking sort order. For example, `Name,Value`

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

checks
if `A`

is sorted by magnitude.

`TF = issorted(`

returns
1 when the elements of the first column of a matrix are sorted. If
the first column contains repeated elements, then `A`

,'rows')`issorted`

looks
at the ordering of the second column to determine `TF`

.
In general, `issorted`

looks to the column immediately
to the right to determine `TF`

when the current and
previous columns have repeated elements.

If

`A`

is a timetable, then`issorted`

checks if the row time vector is in ascending order.This syntax is not supported for a matrix of character vectors.

**Note**

This syntax is not recommended. Use `issortedrows`

instead.

`sort`

| `sortrows`

| `issortedrows`