How do I calculate distances between multiple points on a map using a loop.
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
KSSV
le 1 Déc 2020
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 commentaires
KSSV
le 2 Déc 2020
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.
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!