If you are into biking, running or any other outdoor activity in can be quite entertaining/helpful to record your activities with a GPS. The resulting tracks (in .gpx format) are easily obtainable from for example Garmin devices or the Strava app. Routinely these tracks are overlayed with maps such as Google Maps or Open Streetmap, but it is also possible to take the latitude, longitude and altitude information out of these GPX tracks and plot them in 3D.

Here’s an example how to do this in MATLAB (you need the Mapping Toolbox).

First, add the .gpx file into the MATLAB path folder, here I call it “Bergankunft.gpx”.

Now tell MATLAB to read the .gpx file, extract latitude, longitude, and elevation and plot the obtained information:

route = gpxread(‘Bergankunft_with_Niklas.gpx’);
x = route.Latitude;
y = route.Longitude;
h = route.Elevation;
figure
plot3(x, y, h, ‘b’, ‘LineWidth’, 8)
grid on

Now you have your track as 3D figure and you can manually turn it and study your efforts in 3D 😉

In order to make a video of the whole thing download a MATLAB function created by Alan Jennings which allows you to create a video of any rotating 3D ‘lot (https://ch.mathworks.com/matlabcentral/fileexchange/41093-create-video-of-rotating-3d-plot?s_cid=ME_prod_FX).

I used the following settings:

OptionZ.FrameRate=15;OptionZ.Duration=10;OptionZ.Periodic=true;

CaptureFigVid([-180,10;-360,20;], ‘Bergankunft3D’,OptionZ)

Please also check out Alan’s instructions in order to understand what the variables mean. Most important are frame rate, the total duration, and the angles at which the plot is turning and captured.

The resulting small video (MP4) will be saved in your MATLAB path folder and you can watch it with any media player.

In my case (a trailrun from Lauterbrunnen to the Gspaltenhornhütte in Switzerland) the result looks like this:

Advertisements