categorical

Methods

Method Reference: categorical.issorted

categorical: TF = issorted (C)
categorical: TF = issorted (C, dim)
categorical: TF = issorted (C, direction)
categorical: TF = issorted (C, dim, direction)
categorical: TF = issorted (…, 'MissingPlacement', MP)

Return true if categorical array is sorted.

TF = issorted (C) returns a logical scalar TF, which is true, if the categorical array C is sorted in ascending order, and false otherwise.

TF = issorted (C, dim) returns a logical scalar TF, which is true, if the categorical array C is sorted in ascending order along the dimension dim, and false otherwise.

TF = issorted (A, direction) returns a logical scalar TF, which is true, if the categorical array C is sorted in the direction specified by direction, and false otherwise. direction can be one of the following options:

  • 'ascend', which is the default, checks is elements are in ascending order.
  • 'descend' checks if elements are in descending order.
  • 'monotonic' checks if elements are either in ascending or descending order.
  • 'strictascend' checks if elements are in ascending order and there are no duplicate or undefined elements.
  • 'strictdescend' checks if elements are in descending order and there are no duplicate or undefined elements.
  • 'strictmonotonic' checks if elements are either in ascending or descending order and there are no duplicate or undefined elements.

TF = issorted (…, 'MissingPlacement', MP) specifies where missing elements (<undefined>) are placed with one of the following options specified in MP:

  • 'auto', which is the default, places missing elements last for ascending sort and first for descending sort.
  • 'first' places missing elements first.
  • 'last' places missing elements last.

Source Code: categorical

Example: 1

issorted checks whether an ordinal array is already in non-decreasing category order — a cheap test to skip a needless sort.

 C = categorical ({'S'; 'M'; 'L'}, {'S', 'M', 'L'}, 'Ordinal', true)
C =
  3x1 categorical array

    S    
    M    
    L
 issorted (C)
ans = 1

The same categories out of order:

 issorted (categorical ({'M'; 'S'; 'L'}, {'S', 'M', 'L'}, 'Ordinal', true))
ans = 0