| MATLAB Function Reference | ![]() |
Determine if set elements are in sorted order
Syntax
Description
tf = issorted(A)
returns logical 1 (true) if the elements of vector A are in sorted order, and logical 0 (false) otherwise. Vector A is considered to be sorted if A and the output of sort(A) are equal.
tf = issorted(A, 'rows')
returns logical 1 (true) if the rows of two-dimensional matrix A are in sorted order, and logical 0 (false) 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
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
See Also
sort, sortrows, ismember, unique, intersect, union, setdiff, setxor, is*
| isscalar | isspace | ![]() |
© 1994-2005 The MathWorks, Inc.