How to find an array with all common elements?

2 ビュー (過去 30 日間)
Mariam Shahab
Mariam Shahab 2022 年 11 月 25 日
コメント済み: Mariam Shahab 2022 年 11 月 25 日
Hi all,
Suppose I have the following two arrays:
a= [1 1 1 0 1];
b= [1 0 1 1 0];
I want to find an array that contains each element common to both a and b. So, the elements can be repeated and they have to be in order. I will appreciate any help on this. Thanks!

採用された回答

Walter Roberson
Walter Roberson 2022 年 11 月 25 日
a= [1 1 1 0 1];
b= [1 0 1 1 0];
a(a == b)
ans = 1×2
1 1

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by