Hi,
I want to calculate the distance between two points which i have in longitude and latitude. I have been provided with a matlab code which solves my problem, but i dont have matlab. Can someone help me convert this so i can use excel to solve it?
Thanks in advance.
The code:
%EARTHDIST(Xlong,Ylat,choice) An m-file to compute the distance between the
% points given in the Xlong and Ylat arrays. Returns an array of N-1
% distances where N is the number of points given (must be >= 2).
% Latitudes and longitudes must be in decimal degrees.
%
% There are two ways to do this:
% choice = 1 : distances are between sequential points
% choice = 2 : distances are between each point and the last.
function d=earthdist(x,y,choice)
N=length(x);
if N<2
disp('Must have at least two points')
else
if choice==1
Re=6356.912;
rad=2*pi/360;
alpha=rad.*y(1:N-1)-rad.*y(2:N);
beta=rad.*x(1:N-1)-rad.*x(2:N);
phi=(rad.*y(1:N-1)+rad.*y(2:N))./2;
d=Re.*(alpha.^2+beta.^2 .*cos(phi).^2).^0.5;
else
Re=6356.912;
Bookmarks