| Contents | Index |
Note If you pass non-uniformly spaced points and specify the 'v5cubic' method, interp1 will now issue a warning. In addition, the following syntaxes will be removed or changed in a future release:
For more information, and recommendations for updating your code, see Interpolation and Computational Geometry Functionality Being Removed or Changed. |
yi = interp1(x,Y,xi)
yi = interp1(Y,xi)
yi = interp1(x,Y,xi,method)
yi = interp1(x,Y,xi,method,'extrap')
yi = interp1(x,Y,xi,method,extrapval)
pp = interp1(x,Y,method,'pp')
yi = interp1(x,Y,xi) interpolates to find yi, the values of the underlying function Y at the points in the vector or array xi. x must be a vector. Y can be a scalar, a vector, or an array of any dimension, subject to the following conditions:
If Y is a vector, it must have the same length as x. A scalar value for Y is expanded to have the same length as x. xi can be a scalar, a vector, or a multidimensional array, and yi has the same size as xi.
If Y is an array that is not a vector, the size of Y must have the form [n,d1,d2,...,dk], where n is the length of x. The interpolation is performed for each d1-by-d2-by-...-dk value in Y. The sizes of xi and yi are related as follows:
If xi is a scalar or vector, size(yi) equals [length(xi), d1, d2, ..., dk].
If xi is an array of size [m1,m2,...,mj], yi has size [m1,m2,...,mj,d1,d2,...,dk].
yi = interp1(Y,xi) assumes that x = 1:N, where N is the length of Y for vector Y, or size(Y,1) for matrix Y.
yi = interp1(x,Y,xi,method) interpolates using alternative methods:
For the 'nearest', 'linear', and 'v5cubic' methods, interp1(x,Y,xi,method) returns NaN for any element of xi that is outside the interval spanned by x. For all other methods, interp1 performs extrapolation for out of range values.
yi = interp1(x,Y,xi,method,'extrap') uses the specified interpolation algorithm specified by method to perform extrapolation for out of range values.
yi = interp1(x,Y,xi,method,extrapval) returns the scalar extrapval for out of range values. NaN and 0 are often used for extrapval.
pp = interp1(x,Y,method,'pp') uses the interpolation algorithm specified by method to generate the piecewise polynomial form (ppform) of Y. You can use any of the methods in the preceding table, except for 'v5cubic'. pp can then be evaluated via ppval. ppval(pp,xi) is the same as interp1(x,Y,xi,method,'extrap').
The interp1 command interpolates between data points. It finds values at intermediate points, of a one-dimensional function f(x) that underlies the data. This function is shown below, along with the relationship between vectors x, Y, xi, and yi.

Interpolation is the same operation as table lookup. Described in table lookup terms, the table is [x,Y] and interp1 looks up the elements of xi in x, and, based upon their locations, returns values yi interpolated within the elements of Y.
Generate a coarse sine curve and interpolate over a finer abscissa.
x = 0:10; y = sin(x); xi = 0:.25:10; yi = interp1(x,y,xi); plot(x,y,'o',xi,yi)

Here are two vectors representing the census years from 1900 to 1990 and the corresponding United States population in millions of people.
t = 1900:10:1990;
p = [75.995 91.972 105.711 123.203 131.669...
150.697 179.323 203.212 226.505 249.633];The expression interp1(t,p,1975) interpolates within the census data to estimate the population in 1975. The result is
ans =
214.8585Now interpolate within the data at every year from 1900 to 2000, and plot the result.
x = 1900:1:2000; y = interp1(t,p,x,'spline'); plot(t,p,'o',x,y)

Sometimes it is more convenient to think of interpolation in table lookup terms, where the data are stored in a single table. If a portion of the census data is stored in a single 5-by-2 table,
tab =
1950 150.697
1960 179.323
1970 203.212
1980 226.505
1990 249.633then the population in 1975, obtained by table lookup within the matrix tab, is
p = interp1(tab(:,1),tab(:,2),1975)
p =
214.8585The interp1 command is written in MATLAB. The 'nearest' and 'linear' methods have straightforward implementations.
For the 'spline' method, interp1 calls a function spline that uses the functions ppval, mkpp, and unmkpp. These routines form a small suite of functions for working with piecewise polynomials. spline uses them to perform the cubic spline interpolation. For access to more advanced features, see the spline reference page, the command-line help for these functions, and the Curve Fitting Toolbox™ spline functions.
For the 'pchip' and 'cubic' methods, interp1 calls a function pchip that performs piecewise cubic interpolation within the vectors x and y. This method preserves monotonicity and the shape of the data. See the pchip reference page for more information.
[1] de Boor, C., A Practical Guide to Splines, Springer-Verlag, 1978.
interp2 | interp3 | interpft | interpn | pchip | spline

Explore how to use MATLAB to make advancements in engineering and science.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |