Apply the unwrap function to a 2D matrix. The unwrap function will treat the 2D matrix as a 1D vector (i.e. concatenate each row), meaning that the unwrapped phase of the 2nd row will start at the phase of the end of the first row. Notice that the values in all 5 rows of matrix D are identical, but after the unwrap function is applied, the lines are 'stacked' on top of each other. This is because the unwrap treated the matrix as a large 1D array, rather than treating each row independently.

To apply the unwrap function to 2D phase data in 2D fashion (rather than treating it as a single large 1D vector), see the following example. The unwrap function must be applied to one row at a time, then one column at a time.

Note: A 2D unwrap operation is non-trivial. This example code works in some cases, but not always. Please do some testing to determine if it works for your application.