ismember

  • ismember(A,B) returns a matrix of logical with true for each element of A that exists in B
  • ism = ismember (A, B, 'rows') operates row by row. If A and B are tables, this behaviour is defined by default
  • [ism idx] = ismember(A,B) such as idx contains the lowest indices of each element of A that appears in B

Examples

> A = [1 2 5]#

	1            2            5

> B = [3 2 3; 3 5 3]#

	3            2            3
	3            5            3

> ismember(A, B)#

	0 1 1
 
> [ism idx] = ismember(A, B)

	[ism:1x3 logical]
	[idx:1x3 double]

> ism#

	0 1 1

> idx#

	0            3            4
> A = table(['A';'C';'C';'E'],[1;3;4;2])#

 Col1          Col2
    A             1
    C             3
    C             4
    E             2

> B = table(['A';'C';'D';'E'],[1:4]')#

 Col1          Col2
    A             1
    C             2
    D             3
    E             4

> ismember(A, B)#

	1
	0
	0
	0

Resources

See also

class