Mathematics | ![]() ![]() |
Comparing Interpolation Methods
This example compares two-dimensional interpolation methods on a 7-by-7 matrix of data.
[x,y] = meshgrid(-3:1:3); z = peaks(x,y); surf(x,y,z)
[xi,yi] = meshgrid(-3:0.25:3);
zi1 = interp2(x,y,z,xi,yi,'nearest');
zi2 = interp2(x,y,z,xi,yi,'bilinear');
zi3 = interp2(x,y,z,xi,yi,'bicubic');
Notice that the bicubic method, in particular, produces smoother contours. This is not always the primary concern, however. For some applications, such as medical image processing, a method like nearest neighbor may be preferred because it doesn't generate any "new" data values.
![]() | Two-Dimensional Interpolation | Interpolation and Multidimensional Arrays | ![]() |