|MATLAB Function Reference|
One-dimensional data interpolation (table lookup)
yi = interp1(x,Y,xi) interpolates to find
yi, the values of the underlying function
Y at the points in the vector or array
x must be a vector. Y can be a scalar, a vector, or an array of any dimension, subject to the following conditions:
Yis a scalar or vector, it must have the same length as
x. A scalar value for
Yis expanded to have the same length as the other.
xican be a scalar, a vector, or a multidimensional array, and
yihas the same size as
Yis an array that is not a vector, the size of
Ymust have the form
nis the length of
x. The interpolation is performed for each
Y. The sizes of
yiare related as follows:
yi = interp1(Y,xi)
x = 1:N, where
N is the length of
Y for vector
size(Y,1) for matrix
interpolates using alternative methods:
yi = interp1(x,Y,xi,
||Nearest neighbor interpolation
||Linear interpolation (default)
||Cubic spline interpolation
||Piecewise cubic Hermite interpolation
||(Same as '
||Cubic interpolation used in MATLAB 5
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 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.
0 are often used for
pp = interp1(x,Y,method,'pp') uses the specified method to generate the piecewise polynomial form (ppform) of
Y. You can use any of the methods in the preceding table, except for
interp1 command interpolates between data points. It finds values at intermediate points, of a one-dimensional function that underlies the data. This function is shown below, along with the relationship between vectors
Interpolation is the same operation as table lookup. Described in table lookup terms, the table is
interp1 looks up the elements of
x, and, based upon their locations, returns values
yi interpolated within the elements of
Example 1. Generate a coarse sine curve and interpolate over a finer abscissa.
Example 2. The following multidimensional example creates 2-by-2 matrices of interpolated function values, one matrix for each of the three functions x2, x3, and x4.
yi has size 2-by-2-by-3.
Example 3. Here are two vectors representing the census years from 1900 to 1990 and the corresponding United States population in millions of people.
interp1(t,p,1975) interpolates within the census data to estimate the population in 1975. The result is
Now interpolate within the data at every year from 1900 to 2000, and plot the result.
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,
then the population in 1975, obtained by table lookup within the matrix
Example 4. The following example uses the
'cubic' method to generate the piecewise polynomial form (ppform) of
Y, and then evaluates the result using
interp1 command is a MATLAB M-file. The '
nearest' and '
linear' methods have straightforward implementations.
For the '
interp1 calls a function
spline that uses the functions
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 M-file help for these functions, and the Spline Toolbox.
For the '
interp1 calls a function
pchip that performs piecewise cubic interpolation within the vectors
y. This method preserves monotonicity and the shape of the data. See the
pchip reference page for more information.
 de Boor, C., A Practical Guide to Splines, Springer-Verlag, 1978.
|int8, int16, int32, int64||interp2|
© 1994-2005 The MathWorks, Inc.