intersect

intersect(A,B) returns the set containing all the elements of A belonging also to B.

Examples

>> A = [1 10 2 5 3 7]
B = [10 20 30 1 0]
intersect(A,B)# 

% intersecting numerical values

1 10
>> A = {'John';'Marc';'Sam';'Toni'}
B = {'Emma' 'James' 'Marc' 'Daniel' 'Sam'}
intersect(A,B)# 

% intersecting cell array of strings

[Marc] [Sam]
>> t1 = table([10; 15; 4], {'John';'Marc';'Sam'})#

          Col1  Col2 
            10  John 
            15  Marc 
             4   Sam 

>> t2 = table([15; 4; 15], {'Emma';'James';'Marc'})#

          Col1   Col2 
            15   Emma 
             4  James 
            15   Marc 

>> intersect(t1,t2)#

          Col1  Col2 
            15  Marc  

See also

ismember | isinstr