Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intersection of two cell arrays of strings in MATLAB

I have two cell arrays, X and Y. Each cell array is made up of strings : i.e, X{i} is a string for all i, and so is Y{i}. I would like to find the intersection of the two cell arrays, (presumably a third cell array} that has the strings common to both X and Y.

like image 773
NSR Avatar asked Dec 05 '25 08:12

NSR


1 Answers

There is a single function that does this: intersect

For example:


    >> X = {'a', 'b'; 'c', 'd'};
    >> Y = {'c', 'd', 'e', 'f'};
    >> Z = intersect(X, Y)

    Z = 

        'c'    'd'

like image 113
Colin T Bowers Avatar answered Dec 07 '25 23:12

Colin T Bowers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!