www.gusucode.com > map 案例源码 matlab代码程序 > map/DisplayElevationAndTimeareaMapsExample.m

    %% Display Elevation and Time-area Maps
% Display elevation and time area maps and calculate distance using track
% logs.
%%
% Read track log from the |sample_mixed.gpx| file. 

% Copyright 2015 The MathWorks, Inc.

trk = gpxread('sample_mixed', 'FeatureType', 'track');
%%
% Convert the time value strings to serial date numbers using |datenum|, 
% and then compute the time-of-day in hours-minutes-seconds.
timeStr = strrep(trk.Time, 'T', ' ');
timeStr = strrep(timeStr, '.000Z', '');
trk.DateNumber = datenum(timeStr, 31);
day = fix(trk.DateNumber(1));
trk.TimeOfDay = trk.DateNumber - day;
%%
% Display an area plot of the elevation and time values.
figure
area(trk.TimeOfDay, trk.Elevation)
datetick('x', 13, 'keepticks', 'keeplimits')
ylabel('elevation (meters)')
xlabel('time(Z) hours:minutes:seconds')
title({'Elevation Area Plot', datestr(day)});
%%
% Calculate and display ground track distance. Convert distance in meter to
% distance in U.S. survey mile.
e = wgs84Ellipsoid;
lat = trk.Latitude;
lon = trk.Longitude;
d = distance(lat(1:end-1), lon(1:end-1), lat(2:end), lon(2:end), e);
d = d * unitsratio('sm', 'meter');
%%
% Display the cumulative ground track distance and elapsed time.
trk.ElapsedTime = trk.TimeOfDay - trk.TimeOfDay(1);
figure
line(trk.ElapsedTime(2:end), cumsum(d))
datetick('x', 13)
ylabel('cumulative ground track distance (statute mile)')
xlabel('elapsed time  (hours:minutes:seconds)')
title({'Cumulative Ground Track Distance in Miles', datestr(day),  ...
   ['Total Distance in Miles: ' num2str(sum(d))]});