Results 1 to 2 of 2

Help with adapting a matlab code to vba

Threaded View

h3lla Help with adapting a matlab... 03-07-2012, 03:14 AM
sweep Re: Help with adapting a... 03-07-2012, 04:12 AM
  1. #1
    Registered User
    Join Date
    12-26-2008
    Location
    Sweden
    Posts
    10

    Help with adapting a matlab code to vba

    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;
    Last edited by h3lla; 03-07-2012 at 03:16 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1