![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/285919/image.png)
How to reduce the executation time for the below operation
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
SatyaPrakash Gupta
am 20 Apr. 2020
Kommentiert: SatyaPrakash Gupta
am 22 Apr. 2020
Hi,
Loc = [m*n] ; % size of X has 1500000*2
image_spots = [m*n] ; % size of X has 500000*2
distance_thresh = 0.5;
mask = false([length(Loc),1]);
tic,for i = 1:length(Loc)
if distance_thresh > min(pdist2(Loc(i,:),image_spots))
mask(i)= true;
end
end,toc;
the above for loop take atleast 12mins, is there a method or a way where i can reduce the times for the executation ?
1 Kommentar
Akzeptierte Antwort
Walter Roberson
am 20 Apr. 2020
I suggest that you redesign to use knnsearch https://www.mathworks.com/help/stats/knnsearch.html asking for 1 neighbour, and comparing that one resulting distance to the threshold.
knnsearch with euclidean distance function and as few as 2 dimensions, will construct a quadtree to be able to find the distances much faster. It becomes like a 2D binary search.
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!