find the minimum distances of all points from neighboring points

4 ビュー (過去 30 日間)
HJ
HJ 2021 年 6 月 4 日
回答済み: darova 2021 年 6 月 5 日
When there are a lot of points, I want to find the minimum distances of all points from neighboring points.
It's too slow right now because there are so many dots.
distances = [];
for i = 1:k
for j = 1:k
if i==j
distances(i,j) = 100000;
else
distances(i,j) = pdist2(blobMeasurements(i).Centroid, blobMeasurements(j).Centroid);
end
end
end
[distances_min, distances_min_index] = min(distances);
I need to find the distance from a point to the nearest point
Also, I have to calculate this process for every point.
Is there a good way?

採用された回答

darova
darova 2021 年 6 月 5 日
Program is slow because of pre-allocation and calling pdist2 everytime
try this
D = pdist2(centroid,centroid);
D = D + eye(size(D))*1E5;

その他の回答 (1 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021 年 6 月 4 日
Here is a nice discussion on this issue with some well developed scripts:
https://www.mathworks.com/matlabcentral/answers/309497-finding-minimum-distance-between-two-points?s_tid=answers_rc1-2_p2_MLT
  1 件のコメント
HJ
HJ 2021 年 6 月 4 日
It's a good resource, but the content is different.
I need to find the distance from a point to the nearest point
Also, I have to calculate this process for every point.

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

カテゴリ

Help Center および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by