0
votes

I've got an 1700 x 3 array, with latitude, longitude and metres above sea level. Like this:

51.2551649606487    7.15089717516404    153.110000000000 

51.2552453948075    7.15086528446721    150.160000000000

51.2552903318980    7.15086348124900    150.200000000000

I want to calculate the distance between successive Lat Lon Coordinates, using the Haversine formula, since i have no access to the MATLAB mapping toolbox( https://de.mathworks.com/matlabcentral/fileexchange/38812-latlon-distance).

My question is, how i should change the given code, to read all of the 1700 coordinates directly from my array?

I read/checked the following link: MATLAB function to calculate distance between two coordinates (latitude and longitude). But it doesn't tell me how to read all the 1700 coordinates from my array at once.

Thank you in advance for everybody who is willing to help me!

Best regards

1
It is unclear what you are asking. You don't know how to select items from your data table? You don't want to use for loops? You are aiming for speed? You want to solve it with matrix operations? – GramThanos
Hello GramThanos, my main question is, how do i read all my coordinates at once in the haversine formula? What do i have to do to make that happen? – Leeve Jong

1 Answers

0
votes

If I understand the question correctly, you should be able to split the data into 3 1700 x 1 arrays: latitude, longitude, and elevation. Then apply the haversine formula on those three arrays. (Although the typical haversine function doesn't account for elevation)

coordinates; %1700 x 3 array
latitudes=coordinates(:,1);
longitudes=coordinates(:,2);
elevations=coordinates(:,3);

lat1=0; %coordinates to compare to
long1=0;

earthRadius=6371000;
a=sind((latitudes-lat1)./2).^2 + cosd(latitudes).*cosd(lat1).*sind((longitudes-long1)./2).^2;
c=atan2(sqrt(a),sqrt(1-a));
distances=c*earthRadius;%in meters