How do I calculate distances between multiple points on a map using a loop.
22 ビュー (過去 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
0 件のコメント
回答 (1 件)
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
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.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!