Method Reference: string.ismember

string: TF = ismember (A, B)
string: TF = ismember (A, B, 'rows')
string: [TF, index] = ismember (…)
string: [TF, index] = ismember (…, 'legacy')

Find string elements in a set.

TF = ismember (A, B) returns a logical array TF of the same size as A containing true for each corresponding element of A that is in B and false otherwise. Similarly to NaN values, <missing> elements are not equal with each other and always return false.

TF = ismember (A, B, 'rows') only applies to string matrices with the same number of columns, in which case the logical vector TF contains true for each row of A that is also a row in B. TF has the same number of rows as A.

[TF, index] = ismember (A, B) also returns an index array of the same size as A containing the lowest index in B for each element of A that is a member of B and 0 otherwise. If the 'rows' optional argument is used, then the returning index is a column vector with the same rows as A and it contains the lowest index in B for each row of A that is a member of B and 0 otherwise. If the 'legacy' optional argument is specified, then the highest index of matched elements is returned. Unless multiple matches exist, the 'legacy' option has no effect on the returned index.

Source Code: string

Example: 1

ismember tests, element by element, whether each string appears in a second set.

 s = string ({'apple'; 'kiwi'; 'pear'})
s =
  3x1 string array

    "apple"    
    "kiwi"     
    "pear"
 ismember (s, string ({'apple'; 'pear'}))
ans =

  1
  0
  1