Return equal values between sets.

1 回表示 (過去 30 日間)
Leor Greenberger
Leor Greenberger 2011 年 9 月 21 日
I have two vectors a and b of different lengths that contain integers. How can I return those values that belong in both a and b? Should I use ismember? ismember seems to return a vector of index numbers, but I could just that in a or b:
[tf, index] = ismember(a, b);
c = b(index);
c = a(index); %same?

採用された回答

Wayne King
Wayne King 2011 年 9 月 21 日
How about intersect()?
x = 1:3;
y = 2:5;
[c,Ix,Iy] = intersect(x,y);
intersect() does not give repetitions though.
Wayne
  1 件のコメント
Leor Greenberger
Leor Greenberger 2011 年 9 月 21 日
works perfectly.

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by