remove element from cell based on vector

1 次查看(过去 30 天)
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 个评论
Jan
Jan 2017-7-19
@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.

请先登录,再进行评论。

采纳的回答

Jan
Jan 2017-7-19
编辑:Jan 2017-7-19
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Cell Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by