Suppose C
is your cell array. Then one way to do what you want would be this:
>> C(cellfun('isempty', C)) = {''};
>> logicalArray = ~cellfun('isempty', strfind(C, 'HA'))
strfind
does not accept cell arrays of which some values are not strings. Your cell array happens to have empty values, but of the wrong kind -- []
is double
, not char
. That is the reason you get that error.
So, I simply replace every empty double
with the empty char (''
), and then use strfind
.
Another way around this problem:
>> logicalArray = cellfun(@(x)~isempty(strfind(x,'HA')), C)
but that is a lot slower.