Effacer les filtres
Effacer les filtres

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

10 vues (au cours des 30 derniers jours)
Dc215905
Dc215905 le 5 Oct 2021
Commenté : Dc215905 le 5 Oct 2021
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 commentaire
Matt J
Matt J le 5 Oct 2021
size(A,2) = 525
size(B,2) = 4324438.
Are size(A,1) and size(B,1) irrelevant for some reason?

Connectez-vous pour commenter.

Réponse acceptée

Matt J
Matt J le 5 Oct 2021
Modifié(e) : Matt J le 5 Oct 2021
Br=round(B(:),3);
Ar=round(A);
[~,IDX]=ismember(Ar,Br);

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by