Calculate Euclidean Distance between one point and many others

5 vues (au cours des 30 derniers jours)
Iliqe
Iliqe le 6 Mar 2022
The idea is to calculate the Euclidean distance from certain point to many other points, e.g., we have point with coordiantes 0 0 0 along X, Y, and Z. And we have 10 other points with any coordinates. And the output is vector with 10 distances from our point 0 0 0 to other points.
Is there an efficient way to do it? I wrote my own simple fucntion which calculate the Euclidean distance in a loop. But I have millions of calculataions. And it would be great to have smth fast.

Réponse acceptée

Matt J
Matt J le 6 Mar 2022
xyz=rand(3,10); %points
Dist=vecnorm(xyz,2,1)
Dist = 1×10
1.2806 0.8949 0.8368 1.1284 0.8050 1.1707 1.3917 1.3063 0.9286 1.0914

Plus de réponses (1)

Torsten
Torsten le 6 Mar 2022
Dist = sqrt(X.^2 + Y.^2 + Z.^2)

Catégories

En savoir plus sur Computational Geometry dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by