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

9 ビュー (過去 30 日間)
Charlie Hillary
Charlie Hillary 2020 年 12 月 1 日
コメント済み: Charlie Hillary 2020 年 12 月 2 日
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.
Charlie Hillary
Charlie Hillary 2020 年 12 月 2 日
Ok will do!

サインインしてコメントする。

カテゴリ

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

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by