필터 지우기
필터 지우기

remove common elements from 2 array

조회 수: 53 (최근 30일)
Ricky
Ricky 2013년 7월 25일
댓글: prashanth shyamala 2021년 11월 21일
Hello Everyone,
I have two array Arr1 = [301;302;303;601;602;603]
and I have another Arr2 = [101;102;301;302;303;601;602;603;1010;1200;1249;1352]
I want to remove the common elements from both arrays
so my result should look like
Arr3 = [101;102;1010;1200;1249;1352]
How can I solve this problem
  댓글 수: 5
Daniel Shub
Daniel Shub 2013년 7월 25일
Ricky, what cyclist is saying is that your example misses an important edge condition. There are two obvious solutions that give the same result for your example arrays, but which behave very different in general.
the cyclist
the cyclist 2013년 7월 25일
What do you want the result to be when
Arr1 = [1; 2; 3; 4; 5; 6];
Arr2 = [1; 2; 3; 7; 8; 9];
?

댓글을 달려면 로그인하십시오.

답변 (1개)

the cyclist
the cyclist 2013년 7월 25일
Acommon = intersect(Arr1,Arr2)
Arr3 = setxor(Arr2,Acommon)
will give you the result you mentioned, but see my comment.
  댓글 수: 2
Manjula
Manjula 2017년 11월 30일
Thank you Mr Cyclist for posting the solution
prashanth shyamala
prashanth shyamala 2021년 11월 21일
Brilliant! thanks!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by