function [theta] = get_mean_angle(angles)
% function [theta] = get_mean_angle(angles)
%
% This function returns the average angle in radians for the angles given
% in the vector angles.
%
% Dr. A. I. Hanna (2005).

theta = 0;
if isempty(angles)
    return;
end
angles = angles(:);
for i=2:length(angles)
    if (abs(angles(i-1) - (angles(i)+pi))) <  (abs(angles(i-1) - (angles(i))))
        angles(i) = angles(i)+pi;
    elseif (abs(angles(i-1) - (angles(i)-pi))) <  (abs(angles(i-1) - (angles(i))))
        angles(i) = angles(i)-pi;
    end
end
theta = mean(angles);
return;