% Sample code 6 Feb 2015, Professor Guth for SO503
% this works with one of the Normandy GPS files
% must open the data first file with File, Import data
% Matlab does not like ASCII text for values in the file (after header row)
% Either remove the offending column before importing, or
% convert the Text to a number with a global search and replace
% create a vector from each column of the data
%allocate storage for variables, and zero out the vectors
Hours=zeros(6051,1);
dx=zeros(6050,1);
dy=zeros(6050,1);
heading=zeros(6050,1);
tc=zeros(6050,1);
speed=zeros(6050,1);
filhead=zeros(6050,1);
for i=1:6051,
%don't have time to get the hours right, will come back and fix
%this would work if the first reading was at 1000, and there was one every second
Hours(i) = 10 + i/3600;
end;
for i=1:6050,
dx(i)=X_MERC(i+1)-X_MERC(i);
dy(i)=Y_MERC(i+1)-Y_MERC(i);
tc(i)=(Hours(i+1)+Hours(i))/2;
heading(i)=atan2(dy(i),dx(i));
heading(i)=rad2deg(heading(i));
if heading(i) < 0,
heading(i) = heading(i) + 360;
else
%no need here, we think
end
end;
filsize=13
filhead=filter(ones(1,filsize)/filsize,1,heading);
Figure(1)
f1=plot(tc,heading,tc,filhead);
xlabel('Time (hours)');