📄 computetrackstats.m
字号:
function [ distance, time ] = ComputeTrackStats(track)
% COMPUTETRACKSTATS Compute track log statistics
%
% Compute the length of the track, and the time spent traversing it.
% Sometimes the time may be zero, because Garmin GPS units remove the
% timestamp from saved track logs (though they maintain it in the
% active log).
distance = 0;
time = 0;
for i=1:length([track.waypoints.lat])-1
distance = distance + SphericalDistance(track.waypoints(i), track.waypoints(i+1));
end
% Time stamp stored as seconds, simply subtract end from beginning to
% get duration.
seconds = track.waypoints(i).time - track.waypoints(1).time;
% Covert to hours
time = seconds / 3600;
function d = SphericalDistance(point1, point2)
% SPHERICALDISTANCE Compute the distance between two points on the Earth's
% surface Earth's radius:
% 3437.74677 statue miles
% 6378 kilometers
% 3963 normal miles
% Convert to radians.
deg2rad = (180/pi);
lat1 = point1.lat / deg2rad;
long1 = point1.long / deg2rad;
lat2 = point2.lat / deg2rad;
long2 = point2.long / deg2rad;
% Compute distance in miles
r = 3963;
d = acos( sin(lat1) * sin(lat2) + ...
cos(lat1)*cos(lat2)*cos(long2-long1) ) * r;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -