Calculate Euclidean Distance between one point and many others

조회 수: 5 (최근 30일)
Iliqe
Iliqe 2022년 3월 6일
답변: Matt J 2022년 3월 6일
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에서 Computational Geometry에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by