www.pudn.com > SerialGPS.zip > AnalyzeTracks.m


function AnalyzeTracks(tracks) 
% ANALYZETRACKS Analyze GPS track log data, display charts 
 
for i=1:length(tracks) 
     [ distance, time ] = ComputeTrackStats(tracks(i)); 
     if (time > 0) 
         speed = distance / time; 
     end 
      
    % Convenience variables 
    lat = [tracks(i).waypoints.lat]; 
    long = [tracks(i).waypoints.long]; 
    alt = [tracks(i).waypoints.alt]; 
 
    % Display a figure with four sub-areas of equal size. 
    % Upper left: text statistics 
    % Lower left: 3D view 
    % Upper right: bird's eye view of the track 
    % Lower right: elevation profile 
     
    h = subplot(2,2,[1 2 3 4]); 
     
    % Display the bird's eye view 
    subplot(2,2,2); 
    plot(long, lat); 
    title('Overhead (north up)', 'fontweight', 'bold'); 
    xlabel('Longitude'); 
    ylabel('Latitude'); 
     
    % Display the elevation profile 
    subplot(2,2,4); 
    plot(alt); 
    title('Elevation Profile (feet)', 'fontweight', 'bold'); 
    xlabel('Waypoint number'); 
    ylabel('Feet'); 
     
     
    % Display the 3D data 
    subplot(2,2,3); 
    plot3(long, lat, alt); 
    axis tight; 
    xlabel('Longitude'); 
    ylabel('Latitude'); 
    zlabel('Feet'); 
   
    minAlt = min(alt); 
    for j=1:length(long)-1 
        patch([long(j) long(j+1) long(j+1) long(j)], ... 
              [lat(j) lat(j+1) lat(j+1) lat(j)], ... 
              [alt(j) alt(j+1) minAlt minAlt], 'b'); 
    end 
     
    title('3D Track Data', 'fontweight', 'bold'); 
     
    % Display the statistics 
    subplot(2,2,1); 
    axis off 
     
    % Distance 
    text(0, .85, ['Track length: ' num2str(distance) ' miles.']); 
     
    % Time 
    if (time <= 0) 
        etime = 'Data not available.'; 
    else 
        etime = [num2str(time) ' hours.']; 
    end 
    text(0, .75, ['Elapsed time: ' etime]); 
     
    % Average speed 
    if (time <= 0) 
        aspeed = 'Data not available.'; 
    else 
        aspeed = [ num2str(speed) ' miles/hour.']; 
    end 
    text(0, .65, ['Average speed: ' aspeed]); 
     
    % Start and end points 
    [deg min sec dir] = Decimal2Degrees(tracks(i).waypoints(1).lat, 'latitude'); 
    point = sprintf('%d\\circ %d" %4.2f'' %s', deg, min, sec, dir); 
    text(0, .55, ['Start:']); 
    text(.1, .45, point); 
    [deg min sec dir] = Decimal2Degrees(tracks(i).waypoints(1).long, 'longitude'); 
    point = sprintf('%d\\circ %d" %4.2f'' %s', deg, min, sec, dir); 
    text(.1, .35, point); 
 
    n = length([tracks(i).waypoints(1).lat]); 
    [deg min sec dir] = Decimal2Degrees(tracks(i).waypoints(n).lat, 'latitude'); 
    point = sprintf('%d\\circ %d" %4.2f'' %s', deg, min, sec, dir); 
    text(0, .25, ['End:']); 
    text(.1, .15, point); 
    [deg min sec dir] = Decimal2Degrees(tracks(i).waypoints(n).long, 'longitude'); 
    point = sprintf('%d\\circ %d" %4.2f'' %s', deg, min, sec, dir); 
    text(.1, .05, point); 
 
    % Decorate the figure 
    if (isempty(tracks(i).comment)) 
        title(['Track #' num2str(i) ' of ' num2str(length(tracks))], 'fontweight', 'bold'); 
    else 
        title(['Track ' tracks(i).comment ' (' num2str(i) ' of ' num2str(length(tracks)) ')'], 'fontweight', 'bold'); 
    end 
end 
 
function [deg, min, sec, dir] = Decimal2Degrees(x, type) 
% DECIMAL2DEGREES Convert a decimal degree to degrees, minutes, seconds 
 
deg = floor(x); 
min = 60 * (x - floor(x)); 
sec = 60 * (min - floor(min)); 
min = floor(min); 
 
if (deg > 0) 
    if (strcmp(type, 'latitude')) 
        dir = 'N'; 
    elseif (strcmp(type, 'longitude')) 
        dir = 'W'; 
    end 
else 
    if (strcmp(type, 'latitude')) 
        dir = 'S'; 
    elseif (strcmp(type, 'longitude')) 
        dir = 'E'; 
    end 
end 
 
deg = abs(deg);