Search code examples
stringmatlabcell-array

select subcells based on a different cell string - matlab


Given the following cell array of strings:

a(1) = {{'one', 'two', 'three', 'four'}}
a(2) = {{'one', 'two', 'four', 'five'}}
a(3) = {{'four', 'five', 'six', 'seven'}}

b = {'one', 'two'}

is there a way to check whether both strings in b are contained in each subcell of a?

In my example a(1) and a(2) would fill this requirement.


Solution

  • >> cellfun(@(x) all(ismember(b, x)), a)
    
    ans =
    
         1     1     0