MATLAB: Transform angles that are -180 to +180 to angles that are in the 0-360 degree range

anglesif statementvector coding

I am implementing a vector coding technique in matlab using the atan2d(diff(y),diff(x)) function, but the results are from -180 to +180 and I would like to have a 0-360 range. I tried to input an if statement for angles < 0 to have 360 added to them, but I couldn't get it to work. It is possible that I just didn't write the statement correctly, but I would appreciate any tips or advice.

Best Answer

This is my little anonymous function that I use for such problems:
Angles360 = @(a) rem(360+a, 360); % For ‘atan2d’