table.ismember
table: TF = ismember (tblA, tblB)
table: [TF, ixB] = ismember (tblA, tblB)
Find set members between two tables by rows.
TF = ismember (tblA, tblB) returns a logical
column vector TF with one element per row of tblA, where
TF(i) is true when the -th row of tblA
also appears as a row of tblB. Both tables must have the same
variable names, although not necessarily in the same order, and rows are
compared by their variable values only (row names are ignored).
[TF, ixB] = ismember (tblA, tblB) also
returns a column vector ixB containing, for each row of tblA,
the index of the lowest matching row in tblB, or 0 if there
is no match.
Source Code: table
ismember tests, row by row, whether each row of the first table also occurs in the second — returning a logical column, not a new table. A row counts as a member only when all of its variables match a row of B.
A = table ({'Li'; 'Diaz'; 'Brown'}, [38; 40; 49], ...
categorical ({'NY'; 'CA'; 'MA'}), ...
'VariableNames', {'Name', 'Age', 'State'})
A =
3x3 table
Name Age State
_________ ___ _____
{'Li' } 38 NY
{'Diaz' } 40 CA
{'Brown'} 49 MA
B = table ({'Diaz'; 'Brown'; 'Lee'}, [40; 49; 30], ...
categorical ({'CA'; 'MA'; 'TX'}), ...
'VariableNames', {'Name', 'Age', 'State'})
B =
3x3 table
Name Age State
_________ ___ _____
{'Diaz' } 40 CA
{'Brown'} 49 MA
{'Lee' } 30 TX
ismember (A, B)
ans = 0 1 1
A second output gives, for each matching row, its position in B (0 if none).
[TF, loc] = ismember (A, B); loc
loc = 0 1 2