How do I calculate distances between multiple points on a map using a loop.

3 次查看(过去 30 天)
Hi!
I have worked out how to find out the distance between just 2 coordinates using the mapping toolbox as shown:
[arclen, az] = distance([40.333, -10.036 ], [40.333, -9.46]);
km = deg2km(arclen);
display(km)
This is what I get:
>> stationdist
km =
48.8236
However, I have 32 latitude and longitude pairs. These pairings form a path across the North Atlantic, and I need to find the distance between each latitude&longitude pair.
I need to have Matlab spew out all these distances in between station points, and also each new distance needs to be a sum of previous distances.
I am aware I need to use a loop to do this and call in an array of the lat&lon points.
I want it to look like this, assuming each station is calculated to be roughly 50km apart:
>> stationdist
km =
48.8236
104.2764
150.3973
204.9521
How would I do this? Any hints or words would be much appreciated.
Thanks :)
Charlie

回答(1 个)

KSSV
KSSV 2020-12-1
If (x,y) are your column data. To get the distance between successive points use:
dx = diff(x) ; dy = diff(y) ;
d = sqrt(dx.^2+dy.^2) ;
thesum = cumsum(d) ;
Also have a look on pdist, pdist2.
  3 个评论
KSSV
KSSV 2020-12-2
Run a loop....
I have shown you the distance finding of multiple successive points arrange in a m*2 array.
Also mentioned to read about pdist, pdist2.

请先登录,再进行评论。

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by