remove element from cell based on vector

1 view (last 30 days)
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
  2 Comments
Jan
Jan on 19 Jul 2017
@skysky2000: You have asked many very similar questions now. I asked the same question for clarification many times without getting an answer from you. The description "remove based on d=[1,2]" is neither clear nor unique. Inspite of this, many other contributors in this forum posted bold guesses, which solved your problem magically. Fine! But now it is time for you to learn, how you can write such code by your own. It cannot be the goal, that you let the forum answer dozens of questions about strange cell handling. I cannot imagine in which field of science such processings are needed. But even if there is such a field, the answers given already should give you a strong impression about how you can write your own solution.
But for me, personally, it would be nice already, if you learn how to ask a question with providing the unique and clear definition of what you want to achieve. Otherwise I'm afraid the community wil lost the interest.

Sign in to comment.

Accepted Answer

Jan
Jan on 19 Jul 2017
Edited: Jan on 19 Jul 2017
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.

More Answers (0)

Categories

Find more on Cell Arrays in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!