MATLAB Answers

remove common elements from 2 array

115 views (last 30 days)
Ricky
Ricky on 25 Jul 2013
Commented: Manjula on 30 Nov 2017
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 Comments
the cyclist
the cyclist on 25 Jul 2013
What do you want the result to be when
Arr1 = [1; 2; 3; 4; 5; 6];
Arr2 = [1; 2; 3; 7; 8; 9];
?

Sign in to comment.

Answers (1)

the cyclist
the cyclist on 25 Jul 2013
Acommon = intersect(Arr1,Arr2)
Arr3 = setxor(Arr2,Acommon)
will give you the result you mentioned, but see my comment.
  1 Comment
Manjula
Manjula on 30 Nov 2017
Thank you Mr Cyclist for posting the solution

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by