MATLAB: How to find a certain string in a cell with variable size

cellcellfun

Suppose we have a varying sized cell array, e.g:
TempCell = {{'a1','a2'},{'a3','a4','a8','a7'},{'a2','a1'},{'a9'}};
Now, how to find indices of a certain string (like 'a1') in TempCell and remove those arrays which contain that specific string?:
TempCell = {{'a3','a4','a8','a7'},{'a9'}};
I assume Cellfund would be of use, but I could not find any efficient way to use it (I mean without any loop). Any help is more than welocme!

Best Answer

>> TempCell = {{'a1','a2'},{'a3','a4','a8','a7'},{'a2','a1'},{'a9'}};
>> out = TempCell(~cellfun(@(c)any(strcmp('a1',c)),TempCell));
>> out{:}
ans =
'a3' 'a4' 'a8' 'a7'
ans =
'a9'
Using a loop will actually be more efficient (and faster), but cellfun is much more compact code.