Products & Services Industries Academia Support User Community Company

Learn more about MATLAB   

issorted - Determine whether set elements are in sorted order

Syntax

TF = issorted(A)
TF = issorted(A, 'rows')

Description

TF = issorted(A) returns logical 1 (true) if the elements of A are in sorted order, and logical 0 (false) otherwise. Input A can be a vector or an N-by-1 or 1-by-N cell array of strings. 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

Example 1 — Using issorted on a vector

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

issorted(A)
ans = 
     1

Example 2 — 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

Example 3 — Using issorted on a cell array

x = {'one'; 'two'; 'three'; 'four'; 'five'};
issorted(x)
ans =
     0

y = sort(x)
y = 
    'five'
    'four'
    'one'
    'three'
    'two'

issorted(y)

See Also

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

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS