issorted
Determine if array is sorted
Syntax
Description
TF = issorted(
returns the logical scalar 1 (A
)true
) when the elements ofA
are listed in ascending order and 0 (false
) otherwise.
If
A
is a vector, thenissorted
returns 1 when the vector elements are in ascending order.If
A
is a matrix, thenissorted
returns 1 when each column ofA
is in ascending order.If
A
is a multidimensional array, thenissorted
returns 1 whenA
is in ascending order along the first dimension whose size does not equal 1.If
A
is a timetable, thenissorted
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 theissortedrows
function.
TF = issorted(___,
returns 1 whendirection
)A
is sorted in the order specified bydirection
for any of the previous syntaxes. For example,issorted(A,'monotonic')
returns 1 if the elements ofA
are ascending or descending.
TF = issorted(___,
specifies additional parameters for checking sort order. For example,Name,Value
)issorted(A,'ComparisonMethod','abs')
checks ifA
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, thenA
,'rows')issorted
looks at the ordering of the second column to determineTF
。In general,issorted
looks to the column immediately to the right to determineTF
when the current and previous columns have repeated elements.
If
A
is a timetable, thenissorted
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. Useissortedrows
instead.