function [out] = cal_diff_ang (in)


% function designed to calculate different between two angles
% in should be n by 2 matrix.

tempin=zeros(size(in,1),3);
out = zeros(size(in,1),1);
tempin(:,1) = in(:,2)-in(:,1);
tempin(:,2) = -(in(:,1)+360-in(:,2));
tempin(:,3) = in(:,2)+360-in(:,1);

[dumm,imin]=min(abs(tempin'));

for k=1:size(in,1)
out(k,1)=tempin(k,imin(k));
end
