MATLAB: Finding distance from text data for latitude/longitude and creating new column of data for distance

MATLABplottingtext filetext;

Hello all,
I have a series of text files with latitude/longitude data, in seperate columns, and time in another column. I would liek to use the latitude/longitude data to make a distance vs. time plot.
formula for distance based on lat/long:
R = earths radius (mean radius = 6,371km)
Δlat = lat2lat1
Δlong = long2long1
a = sin²(Δlat/2) + cos(lat1).cos(lat2).sin²(Δlong/2)
c = 2.atan2(a, (1a))
d = R.c
The syntax isnt correct above as its not matlab code, just a formula on the internet.
How would I go about defining a new column of data (distance) by having it find the difference between every point of lat and long and then run the other basic operations to find distance?
the data in the text would follow this format;
Latitude Longitude
51.8885857 -2.159813307
51.888588 -2.159810551
51.88858751 -2.159811237
51.88858772 -2.159810981
51.88858774 -2.159810887
51.88858765 -2.159811144
51.88858779 -2.159810991
51.88858747 -2.159811489
51.88858758 -2.159811597
51.88858755 -2.15981158
51.88858725 -2.159811985
51.88858732 -2.159812218

Best Answer

the diff() function will calculate the difference for you without a loop. Here is a start:
loc = [51.8885857 -2.159813307;...
51.888588 -2.159810551;...
51.88858751 -2.159811237;...
51.88858772 -2.159810981;...
51.88858774 -2.159810887;...
51.88858765 -2.159811144;...
51.88858779 -2.159810991;...
51.88858747 -2.159811489;...
51.88858758 -2.159811597;...
51.88858755 -2.15981158;...
51.88858725 -2.159811985;...
51.88858732 -2.159812218];
dloc = diff(loc);
a = sind(dloc(:,1)./2).^2 + ...
cosd(loc(1:end-1,1)).*cosd(loc(2:end,1)).*sind((dloc(:,2)./2).^2);