Is there a faster or alternative way to use find()?

18 ビュー (過去 30 日間)
Dc215905
Dc215905 2021 年 10 月 5 日
コメント済み: Dc215905 2021 年 10 月 5 日
I have two arrays.
size(A,2) = 525
size(B,2) = 4324438.
I'm trying to find the IDX of B that == A(i). I also have to round and take the first IDX just because of the time resolution of the data.
To achieve this I'm currently doing:
IDX =zeros(1,size(A,2));
for i = 1:size(A,2)
idxCueTemp = find(round(B(:),3)==round(A(i),3));
IDX(i) = idxCueTemp(1);
end
This is painfully slow and is taking ~60s to complete.
Is there a better way?
  1 件のコメント
Matt J
Matt J 2021 年 10 月 5 日
size(A,2) = 525
size(B,2) = 4324438.
Are size(A,1) and size(B,1) irrelevant for some reason?

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

採用された回答

Matt J
Matt J 2021 年 10 月 5 日
編集済み: Matt J 2021 年 10 月 5 日
Br=round(B(:),3);
Ar=round(A);
[~,IDX]=ismember(Ar,Br);
  1 件のコメント
Dc215905
Dc215905 2021 年 10 月 5 日
Amazing, thanks!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by