I have a cell array of strings and I want to match substrings to produce a boolean vector to then extract the elements of interest.
I want strfind to behave like strcmp.
t = {'abcde','bcde','abc','ac'};i = strcmp(t,'bcde') 0 1 0 0
for example – for 'bc', I want:
1 1 1 0
but using strfind, I get :
i = strfind(t,'bc') [2] [1] [2] []
then:
~isempty(i) 1
or:
i==[]
but this returns: 'Undefined function 'eq' for input arguments of type 'cell'.'
I think cellfun() with strfind() and isempty() might work but I'm confused how to use it.
v= cellfun(@(x) strfind(t,'bc'), t, 'UniformOutput', false)v = {1x4 cell} {1x4 cell} {1x4 cell} {1x4 cell}v{1}ans = [2] [1] [2] []
I want boolean array: [1 1 1 0]
Best Answer