View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
GPX file reader

4.4 | 7 ratings Rate this file 29 Downloads (last 30 days) File Size: 2.73 KB File ID: #24154 Version: 1.0
image thumbnail

GPX file reader



%LOADGPX Loads route points from a GPS interchange file

| Watch this File

File Information

% ROUTE = LOADGPX(FILENAME) Loads route point information from a .GPX
% GPS interchange file. This utility is not a general-purpose
% implementation of GPX reading and is intended mostly for reading the
% files output by the "gmap pedometer" tool.
% ROUTE is a Nx6 array where each row is a route point.
% Columns 1-3 are the X, Y, and Z coordinates.
% Columns 4-5 are latitude and longitude
% Column 6 is cumulative route length.
% Note that the mapping of latitude/longitude assumes an approximate spherical
% transformation to rectangular coordinates.
% Additional property/value arguments:
% LOADGPX(...,'ElevationUnits','meters',...) uses meters for elevation
% LOADGPX(...,'Viz',true,...) displays the route and elevation map
% For more information on the gmap pedometer and GPX output:
% See also xmlread

MATLAB release MATLAB 7.7 (R2008b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (9)
24 Apr 2012 François Janod

sorry, I forgot this line, to put before the switch line:


Comment only
24 Apr 2012 François Janod

Useful contribution, but mistakenly computed for meter units. should be like that:
route(:,COL_X:COL_Y) = KM_PER_ARCMINUTE*1000*60*route(:,COL_X:COL_Y);

and forget to take into account latitude. must add this line:
route(:,COL_X) = route(:,COL_X)*cos(lat_mean/180*pi);

all in all should be like that:

case 'feet'
route(:,COL_X:COL_Y) = MILES_PER_ARCMINUTE*5280*60*route(:,COL_X:COL_Y);
route(:,COL_X) = route(:,COL_X)*cos(lat_mean/180*pi); %correction de latitude
distMult = 1/5280; %5280 feets = 1 Mile
case 'meters'
route(:,COL_X:COL_Y) = KM_PER_ARCMINUTE*1000*60*route(:,COL_X:COL_Y);
route(:,COL_X) = route(:,COL_X)*cos(lat_mean/180*pi);
distMult = 1/1000;

14 Mar 2012 Bernd

Bernd (view profile)

very helpful...but I also had to impement the changes from Georg. please think about updating the file

02 Sep 2011 Evan

Evan (view profile)

Can't figure out the units of the X, Y, and Z columns. I did the same as George to get gpx files with trkpt instead of rtept. Also converted time to Matlab serial time using datenum.

Comment only
09 May 2011 Georg Ogris

To read my Garmin data change

ptList = d.getElementsByTagName('rtept');
ptList = d.getElementsByTagName('trkpt');

and add:

tim = pt.getElementsByTagName('time') ;
timChar = char(tim.item(0).getTextContent) ;
route(i,COL_TIMEVEC) = datevec([timChar(1:10) ' ' timChar(12:19)]) ;

before the end of the main for-loop


09 May 2011 Georg Ogris

26 Jul 2010 David Longin

14 Jan 2010 Andrew Bliss

Andrew Bliss (view profile)

This is a useful, good file. A few adjustments could improve it.

To allow the output, 1st line should be:
function route=loadgpx(fileName,varargin)

Calculate range before the viz section, so it can be output too if the viz option is off.

Something about the units is off but I didn't take the time to figure out what is wrong with it... gmaptogpx is outputting elevations in meters, right?


14 Jan 2010 Andrew Bliss

Andrew Bliss (view profile)

Contact us