MATLAB: Remove element from cell based on vector

cell arrays

Dear all,
How to remove elements of a={[1 2] [3] [1 5 2] [2] [ 44 5 66 1 2]} based on d=[1 2]. the answer should be c={[] [3] [5] [] [44 5 66]}
Thanks

Best Answer

One time again:
a = {[1 2] [3] [1 5 2] [2] [ 44 5 66 1 2]};
remove = [1, 2];
for ia = 1:numel(a)
a{ia} = setdiff(a{ia}, remove, 'stable');
end
Or:
for ia = 1:numel(a)
a{ia} = a{ia}(~ismember(a{ia}, remove));
end
or many other methods. Start at reading the documentation of setdiff:
doc setdiff
Then proceed with the "See also" line, which shows you similar commands. Read the Getting Started chapters also. And study the many examples of solutions provided to your questions in the forum. If such solutions use 3 lines of code only, I'm convinced that you can try to program this by your own.