How to reduce the executation time for the below operation

1 回表示 (過去 30 日間)
SatyaPrakash Gupta
SatyaPrakash Gupta 2020 年 4 月 20 日
コメント済み: SatyaPrakash Gupta 2020 年 4 月 22 日
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 件のコメント
darova
darova 2020 年 4 月 20 日
Improve your chances on answer

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

採用された回答

Walter Roberson
Walter Roberson 2020 年 4 月 20 日
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 件のコメント
SatyaPrakash Gupta
SatyaPrakash Gupta 2020 年 4 月 20 日
actually it is bit complicated because i used a grid to extract and filter from 1500000 and after that i got 500000 data and now i have to accociated this data into actual location , therefore redesigning would be not helpful i guess.
it means , there is no other mechanism to reduce the executation code for the above code provided right ?
SatyaPrakash Gupta
SatyaPrakash Gupta 2020 年 4 月 22 日
@Walter :
Thank you for the hint , i finally managed to use knnsearch to associate the locations.
thank you again

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by