Finding elements common to both arrays

Given
A = [1 2 3 6 7 9 10];
B = [4 7 8 10];
How would I determine that 7 and 10 are common to both vectors?
find(ismember(A,B))
appears to return the index of A that has the number(s) shared with B, which is not quite what I want. I want to return the values 7 and 10. How do I do that? I have very large vectors, but here I'm giving a simple example.

 採用された回答

Torsten
Torsten 2022 年 4 月 20 日

0 投票

Use
v = intersect(A,B)

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

製品

リリース

R2021b

質問済み:

2022 年 4 月 20 日

回答済み:

2022 年 4 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by