Find the indeces of common elements of

19 ビュー (過去 30 日間)
pietro
pietro 2015 年 11 月 2 日
コメント済み: pietro 2015 年 11 月 5 日
Hi all,
I have two vectors and I need to find the index of the common elements between the two vectors, but the position of the indeces should be like the first array.
Here an example:
a=[7 10 33];
b=[33 7];
result=[3,1];
I would use setdiff like [C,ia] = setdiff(A,B,'stable'), but C has the same order of array A and I cannot swap A with B. In my case all the elements of B are always included in A.
Thank you
Regards
Pietro

採用された回答

Stephen23
Stephen23 2015 年 11 月 2 日
編集済み: Stephen23 2015 年 11 月 2 日
You can use bsxfun quite effectively for this:
>> a = [7,10,33];
>> b = [33,7];
>> [R,~] = find(bsxfun(@eq,a(:),b))
R =
3
1
  1 件のコメント
pietro
pietro 2015 年 11 月 5 日
thanks!

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by