remove element from cell based on vector

1 Ansicht (letzte 30 Tage)
skysky2000
skysky2000 am 19 Jul. 2017
Kommentiert: skysky2000 am 21 Jul. 2017
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 Kommentare
skysky2000
skysky2000 am 19 Jul. 2017
any suggestion please?
Jan
Jan am 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Jan
Jan am 19 Jul. 2017
Bearbeitet: Jan am 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.

Weitere Antworten (0)

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by