remove element from cell based on vector

1 vue (au cours des 30 derniers jours)
skysky2000
skysky2000 le 19 Juil 2017
Commenté : skysky2000 le 21 Juil 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 commentaires
skysky2000
skysky2000 le 19 Juil 2017
any suggestion please?
Jan
Jan le 19 Juil 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.

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 19 Juil 2017
Modifié(e) : Jan le 19 Juil 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.
  1 commentaire
skysky2000
skysky2000 le 21 Juil 2017
That really helpful... thanks Jan

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Cell Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by