MATLAB Function Reference
issorted

Determine if set elements are in sorted order

Syntax

• ```tf = issorted(A)
tf = issorted(A, 'rows')
```

Description

```tf = issorted(A) ``` returns logical true (`1`) if the elements of vector `A` are in sorted order, and logical false (`0`) otherwise. Vector `A` is considered to be sorted if `A` and the output of `sort``(A)` are equal.

```tf = issorted(A, 'rows') ``` returns logical true (`1`) if the rows of two-dimensional matrix `A` are in sorted order, and logical false (`0`) otherwise. Matrix `A` is considered to be sorted if `A` and the output of `sortrows``(A)` are equal.

Remarks

For character arrays, `issorted` uses ASCII, rather than alphabetical, order.

You cannot use `issorted` on arrays of greater than two dimensions.

Examples

Using `issorted` on a vector:

• ```A = [5 12 33 39 78 90 95 107 128 131];

issorted(A)
ans =
1
```

Using `issorted` on a matrix:

• ```A = magic(5)
A =
17    24     1     8    15
23     5     7    14    16
4     6    13    20    22
10    12    19    21     3
11    18    25     2     9

issorted(A, 'rows')
ans =
0

B = sortrows(A)
B =
4     6    13    20    22
10    12    19    21     3
11    18    25     2     9
17    24     1     8    15
23     5     7    14    16

issorted(B)
ans =
1
```

`sort`, `sortrows`, `ismember`, `unique`, `intersect`, `union`, `setdiff`, `setxor`, is*