remove element from cell based on vector
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
skysky2000
el 19 de Jul. de 2017
Comentada: skysky2000
el 21 de Jul. de 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 comentarios
Jan
el 19 de Jul. de 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.
Respuesta aceptada
Jan
el 19 de Jul. de 2017
Editada: Jan
el 19 de Jul. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Cell Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!