MATLAB: Find index of pattern match

find indexpatternstrings

Hello! I am trying to find index position of a pattern from a string array in a string. for example:
string='Mary had a little lamb';
fcnset=["big","little","small"];
I would want the result as the index of 'little' from the string. I tried the following line, but it doesn't work:
n = find(contains(string,fcnset));
how do I go about it?

Best Answer

>> str = 'Mary had a little lamb';
>> pat = {'big','little','small'};
>> idx = ~cellfun('isempty',strfind(str,pat))
idx =
0 1 0
>> find(idx)
ans = 2