remove common elements from 2 array

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 日
編集済み: Daniel Shub 2013 年 7 月 25 日
What have you tried so far? Have you looked at INTERSECT?
the cyclist
the cyclist 2013 年 7 月 25 日
What if both Arr1 and Arr2 have elements are not part of the intersection? What do you want the output to be?
Ricky
Ricky 2013 年 7 月 25 日
I want Arr3 to be empty
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 日

9 投票

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!

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

質問済み:

2013 年 7 月 25 日

コメント済み:

2021 年 11 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by