Calculate Euclidean Distance between one point and many others

10 次查看(过去 30 天)
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.

采纳的回答

Matt J
Matt J 2022-3-6
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

更多回答(1 个)

Torsten
Torsten 2022-3-6
Dist = sqrt(X.^2 + Y.^2 + Z.^2)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by