File Exchange

image thumbnail


version 1.4 (31.6 KB) by Chad Greene
Simply calculate distance traveled along a lat/lon path


Updated 13 Jan 2015

View License

pathdist returns an array of the cumulative distance traveled along a path.
pathDistance = pathdist(lat,lon)
pathDistance = pathdist(...,LengthUnit)
pathDistance = pathdist(...,track)
pathDistance = pathdist(...,'refpoint',[reflat reflon])

pathDistance = pathdist(lat,lon) returns the cumulative distance traveled along the path given by (lat,|lon|). Distance is in meters by default, referenced to the WGS84 ellipsoid. The pathDistance array will be the same size as lat and lon.

pathDistance = pathdist(...,LengthUnit) specifies any valid length unit. The following are a few LengthUnit options. See documentation for validateLengthUnit for a complete list of options.

meter 'm', 'meter(s)', 'metre(s)' (default)
kilometer 'km', 'kilometer(s)', 'kilometre(s)'
nautical mile 'nm', 'naut mi', 'nautical mile(s)'
foot 'ft', 'international ft','foot', 'international foot', 'feet', 'international feet'
inch 'in', 'inch', 'inches'
yard 'yd', 'yds', 'yard(s)'
mile 'mi', 'mile(s)','international mile(s)'

pathDistance = pathdist(...,track) uses the input string track to specify either a great circle/geodesic or a rhumb line arc. If track equals 'gc' (the default value), then great circle distances are computed on a sphere and geodesic distances are computed on the WGS84 ellipsoid. If track equals 'rh', then rhumb line distances are computed on the WGS84 ellipsoid.

pathDistance = pathdist(...,'refpoint',[reflat reflon]) references the path distance to the point along the path nearest to [reflat reflon]. For this calculation, pathdist finds the point in lat and lon which is nearest to [reflat reflon] and assumes this point along lat,|lon| is the zero point. This is only an approximation, and may give erroneous results in cases of very sharply-curving, crossing, or otherwise spaghetti-like paths; where [reflat reflon] lies far from any point along the path, or where points along the path are spaced far apart.

Comments and Ratings (0)



In this morning's release I accidentally set default units to kilometers. Default units are now meters.

Now includes support for miles, feet, nautical miles, and many more length units.

bug fix.

Now accepts NaN inputs.

MATLAB Release Compatibility
Created with R2012b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.

Learn About Live Editor