Clear Filters
Clear Filters

Efficiently calculate distance between moving point and fixed points

4 views (last 30 days)
I have a grid of point coordinates
to those points defined by X,Y,Z and to another point I want to calculate the distances.
mypoint=[500 700 5];
dist=sqrt( (mypoint(1)-X).^2 + (mypoint(2)-Y).^2 + (mypoint(3)-Z).^2 );
This gives me my distances of mypoint to my grid of points. However, mypoint is changing over time. And for each time step I need all distances. I can do this with a simple for loop, but I was wondering if there is a more efficient way if mypoint is changing over time. Thanks

Answers (1)

Niraj Gadakari
Niraj Gadakari on 28 Sep 2017
You can calculate the distance between the points by vectorization.
Here is a link that discusses calculating the distance between two points using vectorization.


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!