Find element index of one array which is equal to the values from another array

51 ビュー (過去 30 日間)
kaiqiang huang
kaiqiang huang 2019 年 11 月 22 日
コメント済み: ME 2019 年 11 月 22 日
Given two arrays
A = [1,1,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,4];
B = [1,1,1,1,1,1,3,3,3,3];
return C=[1,2,3,4,5,6,11,12,13,14]
The first "3" in B is the 11th value in A.
The values in C is the index of the values in B which exist in A.
Any suggestions?

採用された回答

ME
ME 2019 年 11 月 22 日
A = [1,1,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,4];
B = [1,1,1,1,1,1,3,3,3,3];
u=unique(B);
C=[];
for i=1:numel(u)
C=[C find(A==u(i))];
end
A more elegant solution probably exists but this will work.
  2 件のコメント
kaiqiang huang
kaiqiang huang 2019 年 11 月 22 日
Thank you so much! It works well !
ME
ME 2019 年 11 月 22 日
No problem - happy to help!

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

その他の回答 (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