Adding elements to array without repeating
이전 댓글 표시
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!
채택된 답변
추가 답변 (1개)
Yongjian Feng
2021년 7월 7일
0 개 추천
Use ismember(233, F.a) before adding it to F.a.
댓글 수: 6
Marco Gualtieri
2021년 7월 7일
Yongjian Feng
2021년 7월 7일
Please provide more details. Do you want to merge F.a, F.b, and F.c into a new array, and then get rid of all the duplicated? If so
result = [F.a F.b F.c];
result = unique(result);
Marco Gualtieri
2021년 7월 8일
Marco Gualtieri
2021년 7월 8일
Yongjian Feng
2021년 7월 8일
I can put it to an answer, then you can accept it. This will help the other users. Thanks.
Marco Gualtieri
2021년 7월 8일
카테고리
도움말 센터 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!