To remove rows of A
which contain at least one of the strings in B
Fancy one-liner with two nested cellfuns
and strfind
at its core:
A(all(cell2mat(cellfun(@(b) cellfun(@isempty, strfind(A(:,end),b)).',B, 'uni', 0))),1)
Perhaps the logical indices computed as intermediate result are of interest:
ind = cell2mat(cellfun(@(b) cellfun(@isempty, strfind(A(:,end),b)).',B, 'uni', 0));
A(all(ind),1)
Namely, ~ind
tells you which strings of B
are contained in which rows of A
. In the example,
>> ~ind
ans =
0 0 1 0
0 0 0 1
0 0 0 1
How it works: strfind
tests if each string of B
is in A
, and returns a vector with the corresponding positions. So an empty vector means the string is not present. If that vector is empty for all strings of B
, that row of A
should be selected.