MATLAB Mathematics - SERC - Index of

MATLAB Mathematics - SERC - Index of MATLAB Mathematics - SERC - Index of

serc.iisc.ernet.in
from serc.iisc.ernet.in More from this publisher
15.11.2014 Views

2 Polynomials and Interpolation 2 Generate a finer mesh for interpolation: [xi,yi] = meshgrid(-3:0.25:3); 3 Interpolate using nearest neighbor interpolation: zi1 = interp2(x,y,z,xi,yi,'nearest'); 4 Interpolate using bilinear interpolation: zi2 = interp2(x,y,z,xi,yi,'bilinear'); 5 Interpolate using bicubic interpolation: zi3 = interp2(x,y,z,xi,yi,'bicubic'); 6 Compare the surface plots for the different interpolation methods. 6 6 6 4 4 4 2 2 2 0 0 0 −2 −2 −2 −4 −4 −4 −6 3 2 1 0 −1 −2 −3 −3 −2 −1 0 1 2 3 −6 3 2 1 0 −1 −2 −3 −3 −2 −1 0 1 2 3 −6 3 2 1 0 −1 −2 −3 −3 −2 −1 0 1 2 3 surf(xi,yi,zi1) % nearest surf(xi,yi,zi2) % bilinear surf(xi,yi,zi3) % bicubic 2-14

Interpolation 7 Compare the contour plots for the different interpolation methods. 3 3 3 2 2 2 1 1 1 0 0 0 −1 −1 −1 −2 −2 −2 −3 −3 −2 −1 0 1 2 3 −3 −3 −2 −1 0 1 2 3 −3 −3 −2 −1 0 1 2 3 contour(xi,yi,zi1) % nearest contour(xi,yi,zi2) % bilinear contour(xi,yi,zi3) % 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. Interpolation and Multidimensional Arrays Several interpolation functions operate specifically on multidimensional data. Interpolation Functions for Multidimensional Data Function interp3 interpn ndgrid Description Three-dimensional data interpolation. Multidimensional data interpolation. Multidimensional data gridding (elmat directory). This section discusses • Interpolation of three-dimensional data • Interpolation of higher dimensional data • Multidimensional data gridding 2-15

2 Polynomials and Interpolation<br />

2 Generate a finer mesh for interpolation:<br />

[xi,yi] = meshgrid(-3:0.25:3);<br />

3 Interpolate using nearest neighbor interpolation:<br />

zi1 = interp2(x,y,z,xi,yi,'nearest');<br />

4 Interpolate using bilinear interpolation:<br />

zi2 = interp2(x,y,z,xi,yi,'bilinear');<br />

5 Interpolate using bicubic interpolation:<br />

zi3 = interp2(x,y,z,xi,yi,'bicubic');<br />

6 Compare the surface plots for the different interpolation methods.<br />

6<br />

6<br />

6<br />

4<br />

4<br />

4<br />

2<br />

2<br />

2<br />

0<br />

0<br />

0<br />

−2<br />

−2<br />

−2<br />

−4<br />

−4<br />

−4<br />

−6<br />

3<br />

2<br />

1<br />

0<br />

−1<br />

−2<br />

−3<br />

−3<br />

−2<br />

−1<br />

0<br />

1<br />

2<br />

3<br />

−6<br />

3<br />

2<br />

1<br />

0<br />

−1<br />

−2<br />

−3<br />

−3<br />

−2<br />

−1<br />

0<br />

1<br />

2<br />

3<br />

−6<br />

3<br />

2<br />

1<br />

0<br />

−1<br />

−2<br />

−3<br />

−3<br />

−2<br />

−1<br />

0<br />

1<br />

2<br />

3<br />

surf(xi,yi,zi1)<br />

% nearest<br />

surf(xi,yi,zi2)<br />

% bilinear<br />

surf(xi,yi,zi3)<br />

% bicubic<br />

2-14

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!