Calculate Euclidean Distance between one point and many others

7 views (last 30 days)
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.

Accepted Answer

Matt J
Matt J on 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

More Answers (1)

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

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!