フィルターのクリア

How to search for an array inside another array?

89 ビュー (過去 30 日間)
Tintumon
Tintumon 2020 年 6 月 26 日
コメント済み: Tintumon 2020 年 6 月 26 日
E.g: I have the following array:
a = [1 1; 1 2; 1 3; 1 4; 1 1; 1 4; 1 5];
I want to search for the occurance of each row of the following array inside "a":
b = [1 1; 1 4; 1 5]
The output should be the index location as follows:
idx = [1;5;4;6;7]
I tried the following code. But it does not work:
idx = [];
for i = size(b,1)
temp_idx = find(b(i,:) == a )
idx = [idx; temp_idx];
end
I there any way to do this ?
  2 件のコメント
Rik
Rik 2020 年 6 月 26 日
Why would that be the output? The b array only occurs in a only once: at the bottom.
Tintumon
Tintumon 2020 年 6 月 26 日
I need to do a search for each row of "b" array and check whether that row occurs in array.

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

採用された回答

Rik
Rik 2020 年 6 月 26 日
idx=find(ismember(a,b,'row'))
  1 件のコメント
Tintumon
Tintumon 2020 年 6 月 26 日
It works.. Thank you.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by