Efficiently calculate distance between moving point and fixed points

3 ビュー (過去 30 日間)
T
T 2017 年 9 月 25 日
回答済み: Niraj Gadakari 2017 年 9 月 28 日
Hello,
I have a grid of point coordinates
xval=0:1:5000;
yval=0:1:2000;
zval=1;
[X,Y,Z]=meshgrid(xval,yval,zval);
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

回答 (1 件)

Niraj Gadakari
Niraj Gadakari 2017 年 9 月 28 日
You can calculate the distance between the points by vectorization.
Here is a link that discusses calculating the distance between two points using vectorization.

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by