フィルターのクリア

Find elements in one array not in another

189 ビュー (過去 30 日間)
Sharon
Sharon 2012 年 5 月 29 日
I have
a=1 3 5 6
b=2 4 3 7
I need to find first_set=1 5 6 second_set=2 4 7
I tried
p=ismember(a,b);
first_set=a(~p)
q=ismember(b,a);
second_set=b(~q)
is there an easier way to do this?
  1 件のコメント
Image Analyst
Image Analyst 2012 年 5 月 29 日
Be sure to read and understand the FAQ if you're working with single or double class numbers. http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F Depending on how you get the numbers, they may not be equal even though you think they should be.

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

採用された回答

Thomas
Thomas 2012 年 5 月 29 日
try setdiff
doc setdiff
% in above case
first_Set=setdiff(a,b)
second_set=setdiff(b,a)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by