Method Reference: string.issorted

string: TF = issorted (str)
string: TF = issorted (str, dim)
string: TF = issorted (str, direction)
string: TF = issorted (str, dim, direction)
string: TF = issorted (…, 'MissingPlacement', MP)

Return true if string array is sorted.

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

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

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

  • 'ascend', which is the default, checks if 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 missing elements.
  • 'strictdescend' checks if elements are in descending order and there are no duplicate or missing elements.
  • 'strictmonotonic' checks if elements are either in ascending or descending order and there are no duplicate or missing elements.

TF = issorted (…, 'MissingPlacement', MP) specifies where missing elements (<missing>) 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: string

Example: 1

issorted checks whether the strings are already in alphabetical order.

 issorted (string ({'a'; 'b'; 'c'}))
ans = 1
 issorted (string ({'b'; 'a'; 'c'}))
ans = 0