필터 지우기
필터 지우기

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

조회 수: 3 (최근 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.

댓글을 달려면 로그인하십시오.

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by