Unlike other solutions, but a little clean, because it requires only one simple line of code ...
B = mod(A+pi,2*pi) - pi; A = -20:2:20; mod(A+pi,2*pi) - pi ans = Columns 1 through 12 -1.1504 0.84956 2.8496 -1.4336 0.56637 2.5664 -1.7168 0.28319 2.2832 -2 0 2 Columns 13 through 21 -2.2832 -0.28319 1.7168 -2.5664 -0.56637 1.4336 -2.8496 -0.84956 1.1504
user85109
source share