0
votes
a={'hello','world','friends'};

I want to see if for every word in the cell array contains the letter 'o', how to use cellfun() to achieve the following in a compact expression?

   b = [ contains(a(1),'o')  contains(a(2),'o')  contains(a(3),'o')]
1

1 Answers

2
votes

You don't need cellfun, if you read the documentation, contains works natively on cell arrays of characters:

a = {'hello', 'world', 'friends'};
b = contains(a, 'o');

Which returns:

b =

  1×3 logical array

   1   1   0