ismember
Determine which elements of the first argument exist in the second argument.
Syntax
ismember(x,s)
ismember(x,s,'rows')
[bool, index] = ismember(...)
Inputs
- x
 - Type: double | integer | char | string | logical | struct | cell
 - s
 - The items from which to find possible matches.
 - 'rows'
 - Specify that the search be made for common rows as opposed to common elements.
 
Outputs
- bool
 - A matrix with the same dimenions as x, with each element set to 1 if the corresponding element of x is contained in s, and 0 otherwise.
 - index
 - A matrix with the same dimenions as x that contains indices of s(:) for the matched elements reported in bool, and 0 otherwise.
 
Examples
Matrix example:
[bool, index] = ismember([5 4; 3 6],[7 5 8 9 6])
      bool = [Matrix] 2 x 2
1  0
0  1
index = [Matrix] 2 x 2
2  0
0  5
      String example:
[bool, index] = ismember('abcd','baeg')
      bool = [Matrix] 1 x 4
1  1  0  0
index = [Matrix] 1 x 4
2  1  0  0
      Row example:
ismember([1 2 3; 1 4 5; 1 2 3],[1 2 3],'rows')
      ans = [Matrix] 3 x 1
1
0
1