clc
clear

load M1_1

dif=zeros(length(M1_1),1);
i=1;

% build the matrix of relative movements
for i=1:(length(M1_1)-1)
  dif(i)=M1_1(i+1)-M1_1(i);
end

% sum the relative movement, looking for turns, 
% to find the final heading
turns=0;
sum=0;
for i=1:(length(dif)-1)
  sum=sum+dif(i);
  if sum > 360
   disp('turn detected');
   turns=turns + 1;
  end
  if sum < -360
   disp('turn detected');
   turns = turns + 1;
  end
end

disp('For M1_1, the total change in degrees is:');
sum
% for M1_1, no turns detected, +131 degree relative change

load M1_2

dif=zeros(length(M1_2),1);
i=1;

% build the matrix of relative movements
for i=1:(length(M1_2)-1)
  dif(i)=M1_2(i+1)-M1_2(i);
end

% sum the relative movement, looking for turns, 
% to find the final heading
turns=0;
sum=0;
for i=1:(length(dif)-1)
  sum=sum+dif(i);
  if sum > 360
   disp('turn detected');
   turns=turns + 1;
  end
  if sum < -360
   disp('turn detected');
   turns = turns + 1;
  end
end

disp('For M1_2, the total change in degrees is:');
sum
% for M1_2, no turns detected, -66 degree relative change


load M1_3

dif=zeros(length(M1_3),1);
i=1;

% build the matrix of relative movements
for i=1:(length(M1_3)-1)
  dif(i)=M1_3(i+1)-M1_3(i);
end

% sum the relative movement, looking for turns, 
% to find the final heading
turns=0;
sum=0;
for i=1:(length(dif)-1)
  sum=sum+dif(i);
  if sum > 360
   disp('turn detected');
   turns=turns + 1;
  end
  if sum < -360
   disp('turn detected');
   turns = turns + 1;
  end
end

disp('For M1_3, the total change in degrees is:');
sum
% for M1_3, no turns detected, -188 degree relative change

load M1_4

dif=zeros(length(M1_4),1);
i=1;

% build the matrix of relative movements
for i=1:(length(M1_4)-1)
  dif(i)=M1_4(i+1)-M1_4(i);
end

% sum the relative movement, looking for turns, 
% to find the final heading
turns=0;
sum=0;
for i=1:(length(dif)-1)
  sum=sum+dif(i);
  if sum > 360
   disp('turn detected');
   turns=turns + 1;
  end
  if sum < -360
   disp('turn detected');
   turns = turns + 1;
  end
end

disp('For M1_4, the total change in degrees is:');
sum
% for M1_4, no turns detected, -56 degree relative change

load M1_5

dif=zeros(length(M1_5),1);
i=1;

% build the matrix of relative movements
for i=1:(length(M1_5)-1)
  dif(i)=M1_5(i+1)-M1_5(i);
end

% sum the relative movement, looking for turns, 
% to find the final heading
turns=0;
sum=0;
for i=1:(length(dif)-1)
  sum=sum+dif(i);
  if sum > 360
   disp('turn detected');
   turns=turns + 1;
  end
  if sum < -360
   disp('turn detected');
   turns = turns + 1;
  end
end

disp('For M1_5, the total change in degrees is:');
sum
% for M1_5, no turns detected, -81.2 degree relative change

load M1_6

dif=zeros(length(M1_6),1);
i=1;

% build the matrix of relative movements
for i=1:(length(M1_6)-1)
  dif(i)=M1_6(i+1)-M1_6(i);
end

% sum the relative movement, looking for turns, 
% to find the final heading
turns=0;
sum=0;
for i=1:(length(dif)-1)
  sum=sum+dif(i);
  if sum > 360
   disp('turn detected');
   turns=turns + 1;
  end
  if sum < -360
   disp('turn detected');
   turns = turns + 1;
  end
end

disp('For M1_6, the total change in degrees is:');
sum
% for M1_6, no turns detected, -83.3 degree relative change

load M1_7

dif=zeros(length(M1_7),1);
i=1;

% build the matrix of relative movements
for i=1:(length(M1_7)-1)
  dif(i)=M1_7(i+1)-M1_7(i);
end

% sum the relative movement, looking for turns, 
% to find the final heading
turns=0;
sum=0;
for i=1:(length(dif)-1)
  sum=sum+dif(i);
  if sum > 360
   disp('turn detected');
   turns=turns + 1;
  end
  if sum < -360
   disp('turn detected');
   turns = turns + 1;
  end
end

disp('For M1_7, the total change in degrees is:');
sum
% for M1_7, no turns detected, -35.2 degree relative change

load M1_8

dif=zeros(length(M1_8),1);
i=1;

% build the matrix of relative movements
for i=1:(length(M1_8)-1)
  dif(i)=M1_8(i+1)-M1_8(i);
end

% sum the relative movement, looking for turns, 
% to find the final heading
turns=0;
sum=0;
for i=1:(length(dif)-1)
  sum=sum+dif(i);
  if sum > 360
   disp('turn detected');
   turns=turns + 1;
  end
  if sum < -360
   disp('turn detected');
   turns = turns + 1;
  end
end

disp('For M1_8, the total change in degrees is:');
sum
% for M1_8, no turns detected, -196.96 degree relative change


load M2_1

dif=zeros(length(M2_1),1);
i=1;

% build the matrix of relative movements
for i=1:(length(M2_1)-1)
  dif(i)=M2_1(i+1)-M2_1(i);
end

% sum the relative movement, looking for turns, 
% to find the final heading
turns=0;
sum=0;
for i=1:(length(dif)-1)
  sum=sum+dif(i);
  if sum > 360
   disp('turn detected');
   turns=turns + 1;
  end
  if sum < -360
   disp('turn detected');
   turns = turns + 1;
  end
end

disp('For M2_1, the total change in degrees is:');
sum
% for M2_1, no turns detected, -313 degree relative change

load M2_2

dif=zeros(length(M2_2),1);
i=1;

% build the matrix of relative movements
for i=1:(length(M2_2)-1)
  dif(i)=M2_2(i+1)-M2_2(i);
end

% sum the relative movement, looking for turns, 
% to find the final heading
turns=0;
sum=0;
for i=1:(length(dif)-1)
  sum=sum+dif(i);
  if sum > 360
   disp('turn detected');
   turns=turns + 1;
  end
  if sum < -360
   disp('turn detected');
   turns = turns + 1;
  end
end

disp('For M2_2, the total change in degrees is:');
sum
% for M2_2, no turns detected, -67 degree relative change

load M2_3

dif=zeros(length(M2_3),1);
i=1;

% build the matrix of relative movements
for i=1:(length(M2_3)-1)
  dif(i)=M2_3(i+1)-M2_3(i);
end

% sum the relative movement, looking for turns, 
% to find the final heading
turns=0;
sum=0;
for i=1:(length(dif)-1)
  sum=sum+dif(i);
  if sum > 360
   disp('turn detected');
   turns=turns + 1;
  end
  if sum < -360
   disp('turn detected');
   turns = turns + 1;
  end
end

disp('For M2_3, the total change in degrees is:');
sum
% for M2_3, no turns detected, -279 degree relative change

load M2_4

dif=zeros(length(M2_4),1);
i=1;

% build the matrix of relative movements
for i=1:(length(M2_4)-1)
  dif(i)=M2_4(i+1)-M2_4(i);
end

% sum the relative movement, looking for turns, 
% to find the final heading
turns=0;
sum=0;
for i=1:(length(dif)-1)
  sum=sum+dif(i);
  if sum > 360
   disp('turn detected');
   turns=turns + 1;
  end
  if sum < -360
   disp('turn detected');
   turns = turns + 1;
  end
end

disp('For M2_4, the total change in degrees is:');
sum
% for M2_4, no turns detected, -135 degree relative change

load M2_5

dif=zeros(length(M2_5),1);
i=1;

% build the matrix of relative movements
for i=1:(length(M2_5)-1)
  dif(i)=M2_5(i+1)-M2_5(i);
end

% sum the relative movement, looking for turns, 
% to find the final heading
turns=0;
sum=0;
for i=1:(length(dif)-1)
  sum=sum+dif(i);
  if sum > 360
   disp('turn detected');
   turns=turns + 1;
  end
  if sum < -360
   disp('turn detected');
   turns = turns + 1;
  end
end

disp('For M2_5, the total change in degrees is:');
sum
% for M2_5, no turns detected, -56 degree relative change

load M2_6

dif=zeros(length(M2_6),1);
i=1;

% build the matrix of relative movements
for i=1:(length(M2_6)-1)
  dif(i)=M2_6(i+1)-M2_6(i);
end

% sum the relative movement, looking for turns, 
% to find the final heading
turns=0;
sum=0;
for i=1:(length(dif)-1)
  sum=sum+dif(i);
  if sum > 360
   disp('turn detected');
   turns=turns + 1;
  end
  if sum < -360
   disp('turn detected');
   turns = turns + 1;
  end
end

disp('For M2_6, the total change in degrees is:');
sum
% for M2_6, no turns detected, -56 degree relative change

load M2_7

dif=zeros(length(M2_7),1);
i=1;

% build the matrix of relative movements
for i=1:(length(M2_7)-1)
  dif(i)=M2_7(i+1)-M2_7(i);
end

% sum the relative movement, looking for turns, 
% to find the final heading
turns=0;
sum=0;
for i=1:(length(dif)-1)
  sum=sum+dif(i);
  if sum > 360
   disp('turn detected');
   turns=turns + 1;
  end
  if sum < -360
   disp('turn detected');
   turns = turns + 1;
  end
end

disp('For M2_7, the total change in degrees is:');
sum
% for M2_7, no turns detected, -56 degree relative change

load M2_8

dif=zeros(length(M2_8),1);
i=1;

% build the matrix of relative movements
for i=1:(length(M2_8)-1)
  dif(i)=M2_8(i+1)-M2_8(i);
end

% sum the relative movement, looking for turns, 
% to find the final heading
turns=0;
sum=0;
for i=1:(length(dif)-1)
  sum=sum+dif(i);
  if sum > 360
   disp('turn detected');
   turns=turns + 1;
  end
  if sum < -360
   disp('turn detected');
   turns = turns + 1;
  end
end

disp('For M2_8, the total change in degrees is:');
sum
% for M2_8, no turns detected, -56 degree relative change
 
load M3_1

dif=zeros(length(M3_1),1);
i=1;

% build the matrix of relative movements
for i=1:(length(M3_1)-1)
  dif(i)=M3_1(i+1)-M3_1(i);
end

% sum the relative movement, looking for turns, 
% to find the final heading
turns=0;
sum=0;
for i=1:(length(dif)-1)
  sum=sum+dif(i);
  if sum > 360
   disp('turn detected');
   turns=turns + 1;
  end
  if sum < -360
   disp('turn detected');
   turns = turns + 1;
  end
end

disp('For M3_1, the total change in degrees is:');
sum
% for M3_1, no turns detected, -56 degree relative change

