Code covered by the BSD License  

Highlights from
Distance calculation using Haversine formula

4.0

4.0 | 1 rating Rate this file 37 Downloads (last 30 days) File Size: 2.56 KB File ID: #27785

Distance calculation using Haversine formula

by Josiah Renfree

 

27 May 2010

Compute the distance between two locations using the Haversine formula

| Watch this File

File Information
Description

This program calculates the distance between two locations (latitude and longitude) using the Haversine formula. The Haversine formula gives the shortest distance between two points over the earth's surface, ignoring elevation, hills, etc...

The program accepts two inputs that can be locations specified as either degrees, minutes, and seconds or by decimal degrees. The output is the distance in km, n.mi, and miles.

Examples:

haversine('53 08 50N, 001 50 58W', '52 12 16N, 000 08 26E') returns 170.2547

haversine([53.1472 -1.8494], '52 12.16N, 000 08.26E') returns 170.2508

haversine([53.1472 -1.8494], [52.2044 0.1406]) returns 170.2563

MATLAB release MATLAB 7.9 (2009b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
31 Jul 2011 Jamie

A very useful function.

Seems to require the function deg2rad

Would be great if it were vectorized so that it could be used with pdist.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
haversine Josiah Renfree 28 May 2010 09:41:44
latitude Josiah Renfree 28 May 2010 09:41:44
longitude Josiah Renfree 28 May 2010 09:41:44
distance Josiah Renfree 28 May 2010 09:41:44
long Josiah Renfree 28 May 2010 09:41:44
lat Josiah Renfree 28 May 2010 09:41:44
haversine murat 17 Apr 2012 19:01:04

Contact us at files@mathworks.com