MATLAB Function Reference
  Go to function:
    Search    Help Desk 
interp1    Examples   See Also

One-dimensional data interpolation (table lookup)

Syntax

Description

yi = interp1(x,Y,xi) returns vector yi containing elements corresponding to the elements of xi and determined by interpolation within vectors x and Y. The vector x specifies the points at which the data Y is given. If Y is a matrix, then the interpolation is performed for each column of Y and yi will be length(xi)-by-size(Y,2). Out of range values are returned as NaNs.

yi = interp1(x,Y,xi,method) interpolates using alternative methods:

All the interpolation methods require that x be monotonic. For faster interpolation when x is equally spaced, use the methods '*linear', '*cubic', '*nearest', or '*spline'.

The interp1 command interpolates between data points. It finds values of a one-dimensional function f(x) underlying the data at intermediate points. This 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 tab = [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.

Examples

Here are two vectors representing the census years from 1900 to 1990 and the corresponding United States population in millions of people.

The expression 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 tab, is

Algorithm

The interp1 command is a MATLAB M-file. The 'nearest', 'linear' and 'cubic' methods have fairly straightforward implementations. For the 'spline' method, interp1 calls a function spline that uses the M-files ppval, mkpp, and unmkpp. These routines form a small suite of functions for working with piecewise polynomials. spline uses them in a fairly simple fashion to perform cubic spline interpolation. For access to the more advanced features, see these M-files and the Spline Toolbox.

See Also

interpft    One-dimensional interpolation using the FFT method.

interp2     Two-dimensional data interpolation (table lookup)

interp3     Three-dimensional data interpolation (table lookup)

interpn     Multidimensional data interpolation (table lookup)

spline      Cubic spline interpolation

References

[1] de Boor, C. A Practical Guide to Splines, Springer-Verlag, 1978.



[ Previous | Help Desk | Next ]