| MATLAB Function Reference | ![]() |
VI = interpn(X1,X2,X3,...,V,Y1,Y2,Y3,...)
VI = interpn(V,Y1,Y2,Y3,...)
VI = interpn(V,ntimes)
VI = interpn(...,method)
VI = interpn(...,method,extrapval)
VI = interpn(X1,X2,X3,...,V,Y1,Y2,Y3,...) interpolates to find VI, the values of the underlying multidimensional function V at the points in the arrays Y1, Y2, Y3, etc. For an n-dimensional array V, interpn is called with 2*N+1 arguments. Arrays X1, X2, X3, etc. specify the points at which the data V is given. Out of range values are returned as NaNs. Y1, Y2, Y3, etc. must be arrays of the same size, or vectors. Vector arguments that are not the same size, and have mixed orientations (i.e. with both row and column vectors) are passed through ndgrid to create the Y1, Y2, Y3, etc. arrays. interpn works for all n-dimensional arrays with 2 or more dimensions.
VI = interpn(V,Y1,Y2,Y3,...) interpolates as above, assuming X1 = 1:size(V,1), X2 = 1:size(V,2), X3 = 1:size(V,3), etc.
VI = interpn(V,ntimes) expands V by interleaving interpolates between each element, working recursively for ntimes iterations. interpn(V) is the same as interpn(V,1).
VI = interpn(...,method) specifies alternative methods:
Nearest neighbor interpolation | |
Linear interpolation (default) | |
Cubic spline interpolation | |
Cubic interpolation, as long as data is uniformly-spaced. Otherwise, this method is the same as 'spline'. |
VI = interpn(...,method,extrapval) specifies a method and a value for VI outside of the domain created by X1, X2, .... Thus, VI equals extrapval for any value of Y1, Y2,... that is not spanned by X1, X2,... respectively. You must specify a method to use extrapval. The default method is 'linear'.
interpn requires that X1, X2, X3, ... be monotonic and plaid (as if they were created using ndgrid). X1, X2, X3, and so on can be non-uniformly spaced.
All the interpolation methods require that X1,X2, X3 ... be monotonic and have the same format ("plaid") as if they were created using ndgrid. X1,X2,X3,... and Y1, Y2, Y3, etc. can be non-uniformly spaced. For faster interpolation when X1, X2, X3, etc. are equally spaced and monotonic, use the methods '*linear', '*cubic', or '*nearest'.
Start by defining an anonymous function to compute
:
f = @(x,y,z,t) t.*exp(-x.^2 - y.^2 - z.^2);
Build the lookup table by evaluating the function f on a grid constructed by ndgrid:
[x,y,z,t] = ndgrid(-1:0.2:1,-1:0.2:1,-1:0.2:1,0:2:10); v = f(x,y,z,t);
Now construct a finer grid:
[xi,yi,zi,ti] = ndgrid(-1:0.05:1,-1:0.08:1,-1:0.05:1, ...
0:0.5:10);Compute the spline interpolation at xi, yi, zi, and ti:
vi = interpn(x,y,z,t,v,xi,yi,zi,ti,'spline');
Plot the interpolated function, and then create a movie from the plot:
nframes = size(ti, 4);
for j = 1:nframes
slice(yi(:,:,:,j), xi(:,:,:,j), zi(:,:,:,j), ...
vi(:,:,:,j),0,0,0);
caxis([0 10]);
M(j) = getframe;
end
movie(M);

interp1, interp2, interp3, ndgrid
![]() | interpft | interpstreamspeed | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |