Method Reference: string.unique

string: B = unique (A)
string: B = unique (A, 'rows')
string: [B, ixA, ixB] = unique (…)
string: … = unique (…, order)
string: … = unique (…, occurrence)

Unique values in a string array.

B = unique (A) returns the unique values of the string array A in the string vector B sorted lexicographically. If If A is a column vector, then B is also a column vector, otherwise unique returns a row vector.

B = unique (A, 'rows') returns the unique rows of the string matrix A in the string matrix B sorted in lexicographical order.

[B, ixA, ixB] = unique (…) also returns index vectors ixA and ixB such that B = A(ixA) and A = B(ixB), unless the 'rows' optional argument is given, in which case B = A(ixA,:) and A = B(ixB,:).

… = unique (…, order) also specifies the order of the returned unique values. order may be either 'sorted', which is the default behavior, or 'stable', in which case the unique values are returned in order of appearance.

… = unique (…, occurrence) also specifies the which index is returned in ixA, where there are repeated values or rows (if opted) in the input categorical array. occurrence may be either 'first', which is the default and returns the index of the first occurrence of each unique value, or 'last', in which case the last occurrence of each unique value is returned.

Source Code: string

Example: 1

unique returns the distinct strings in an array, sorted.

 s = string ({'b'; 'a'; 'b'; 'c'; 'a'})
s =
  5x1 string array

    "b"    
    "a"    
    "b"    
    "c"    
    "a"
 unique (s)
ans =
  3x1 string array

    "a"    
    "b"    
    "c"