No BSD License  

Highlights from
mixture of rem and mod

from mixture of rem and mod by Andr?
mod(x,180) will for any x return the same direction (right sign) but between -90 and +90

[x]=remod(a,f);
function [x]=remod(a,f);
% provides a middle path of rem() and mod(). Will deliver the result that
% is nearer to zero; Handy for eg. directionalities rem(-170,180) is -170
% while mod(-170,180) is 10, while mod(-20,180) is 160...
if size(a,2)~=1;
    error('No arrays allowed, just one-column-vectors');
end
x = mod(a-(f/2),f)-f/2;
end

Contact us at files@mathworks.com