yi = interp1(x,y,xi)yi = interp1(x,y,xi,'method')
interp1 interpolates between data points. It finds values of a one-dimensional function underlying the data at intermediate points.
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.
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.
interp1 performs multiple output table lookup if y is a matrix. If y is a matrix with length(x) rows, and n columns, interp1 returns a length(xi)-by-n matrix yi containing the multi-output table lookup results.
yi = interp1(x,y,xi,'method') specifies alternative interpolation methods, where method can be:
'linear'for linear interpolation
'spline' for cubic spline interpolation
'cubic' for cubic interpolation
All the interpolation methods require that x be monotonic. The 'cubic' method also requires that x contain uniformly spaced points.
The expressiont = 1900:10:1990;p = [75.995 91.972 105.711 123.203 131.669 ...150.697 179.323 203.212 226.505 249.633];
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.ans =214.8585
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 single 5-by-2 table,
then the population in 1975, obtained by table lookup within the matrixtab =1950 150.6971960 179.3231970 203.2121980 226.5051990 249.633
tab, is
p = interp1(tab(:,1),tab(:,2),1975)p =214.8585
interp1 is a MATLAB M-file. The 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.
griddata,interp2,interpft
(c) Copyright 1994 by The MathWorks, Inc.