# changing angular data to remove the sharp changes

I have a 200 by 200 matrice named theta which shows an angle in a 200 by 200 box. The angle is in the interval [-90,90]. When I plot theta in a 2d plane, there are some positions in which the angle jumps from -90 to 90. This is shown for a particular choice case in the below picture:

As it is clear from the picture, there are positions where theta jumps from -80 to 80. I want to make theta even by adding (or subtracting) 180 to it in the positions with sharp change. The reason that I can only add (or subtract) 180 is that in the problem that I am trying to solve, has a symmetry which allows adding 180 degrees to the data. I appreciate it if someone could solve this problem.

The script that I use to plot it is:

[a, b] = contourf(theta, 88);
set(b,'EdgeColor','none');
colormap(summer);
colorbar;


Using the proposed answer I get the following:

Could you do something like: (1/2)*unwrap(2*theta)?

edit: More concretely, I think about this. I would think that the numerical example and asserts are sufficient to see if it can be adapted to your situation.

It is standard usage of the unwrap() function to replace large jumps with the "phase alias" that cause the smallest jump in phase, applied to a 2-d input. As unwrap expects radians rather than degrees, I have to convert back and forth, and as your phase "aliases" at 180 degrees rather than 360, I am scaling by 2 and 1/2.

th = repmat([70 80 -90 -80], 2, 1)
th =

70    80   -90   -80
70    80   -90   -80

th2 = 2*th;