Borrar filtros
Borrar filtros

Adding elements to array without repeating

16 visualizaciones (últimos 30 días)
Marco Gualtieri
Marco Gualtieri el 7 de Jul. de 2021
Comentada: Marco Gualtieri el 8 de Jul. de 2021
Hello,
my question is the following: I have a struct file and I need to add all the elements in the vectors contained in the struct in a single vector without repeating them. My struct is shaped like this:
F.a=[226;227;228;229;290]
F.b=[52;102;230;231;232;233;234;235]
F.c=[37;233;234;235]
and so on. I need to put all the elements of the vectors together but avoiding, for example, to show 233, 234 and 235 twice. Is there a way to do that?
Thank you in advance for your answers!

Respuesta aceptada

Yongjian Feng
Yongjian Feng el 8 de Jul. de 2021
This will work:
result = [F.a F.b F.c];
result = unique(result);

Más respuestas (1)

Yongjian Feng
Yongjian Feng el 7 de Jul. de 2021
Use ismember(233, F.a) before adding it to F.a.
  6 comentarios
Yongjian Feng
Yongjian Feng el 8 de Jul. de 2021
I can put it to an answer, then you can accept it. This will help the other users. Thanks.
Marco Gualtieri
Marco Gualtieri el 8 de Jul. de 2021
You're welcome, thank you for your help!

Iniciar sesión para comentar.

Categorías

Más información sobre Structures 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!

Translated by