function cp = fixAngle2d(x) % compass360(x) -- Change values outside [0, 360] to a 360 degree scale. % % Change to a 360 degree scale. For instance, if x = 440, then x should % really be 80 (since it's 80 degrees past 360). Make sure 360 is always % reported as 0. We need to make it recursive so multiple versions of % 360 just keep "going around" (i.e. 720 must be reported as 0, etc). % This will fail if you give it numbers > 10000, but that should work % well enough for all cases I can possibly imagine. if (abs(x) > 2000 * 360) % Work around the 200 function recursion limit by chopping out some % of the excess z = x - (2000 * 360); cp = compass360(z); % recursion step else if (x > 360) y = x - 360; cp = compass360(y); % recursion step elseif (x == 360) cp = 0; elseif (x < 0) y = x + 360; cp = compass360(y); % recursion step else cp = x; end; end