I want to use cellfun function on strfind function to find the index of each string in a cell array of string in another cell array of strings to exclude them from it.
strings = {'aaa','bbb','ccc','ddd','eee','fff','ggg','hhh','iii','jjj'};
excludedStrings = {'b','g','h'};
idx = cellfun('strfind',strings,excludedStrings);
idx = cell2mat = idx;
idx = reshap(idx,numel(idx),1);
idx = unique(idx);
strings(cell2mat(idx)) = [];
There’s error in the cellfun call line, how can I fix this?
Here’s a lovely one-liner:
Breakdown:
regexprep'').It will automatically repeat this action on all elements in the cell-array
string.If you also wish to remove any empty strings from the cell
string, do this after the command above: