I have a cell array like
a={'potential'; 'impact'; 'of'; 'stranded'; 'assets'; 'and'; 'other'; 'necessary'; 'regulatory'; 'approvals'; 'assets'}
and want to subtract from it an array like b={‘a’; ‘and’; ‘of’; ‘my’; ‘#’}.
Using setdiff(a,b) sorts my array after the difference is computed. What I want is to eliminate from a all the elements present in b without sorting a. Also the repetitions should be preserved, for eg. ‘assets’ in array a should appear at two locations in final array.
The following code I am using does the job:
for i = 1:length(b)
tf = ~strcmp(b(i),a)
a = a(tf,:)
end
But the problem is that array b contains more than 200 string elements which slows down my code considerably. Is there a better way to do this?
1 Answer