interp1 (MATLAB Functions) (2024)

MATLAB Function Reference
interp1

One-dimensional data interpolation (table lookup)

Syntax

  • 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')

Description

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 scalar or vector, it must have the same length as x. A scalar value for x or Y is expanded to have the same length as the other. 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:

'nearest'
Nearest neighbor interpolation
'linear'
Linear interpolation (default)
'spline'
Cubic spline interpolation
'pchip'
Piecewise cubic Hermite interpolation
'cubic'
(Same as 'pchip')
'v5cubic'
Cubic interpolation used in MATLAB 5

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 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 specified method to generate the piecewise polynomial form (ppform) of Y. You can use any of the methods in the preceding table, except for 'v5cubic'.

The interp1 command interpolates between data points. It finds values at intermediate points, of a one-dimensional function interp1 (MATLAB Functions) (3) that underlies the data. This function is shown below, along with the relationship between vectors x, Y, xi, and yi.

interp1 (MATLAB Functions) (4)

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.

    Note interp1q is quicker than interp1 on non-uniformly spaced data because it does no input checking. For interp1q to work properly, x must be a monotonically increasing column vector and Y must be a column vector or matrix with length(X) rows. Type help interp1q at the command line for more information.

Examples

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.

  • x = [1:10]'; y = [ x.^2, x.^3, x.^4 ]; xi = [1.5, 1.75; 7.5, 7.75]; yi = interp1(x,y,xi);

The result yi has size 2-by-2-by-3.

  • size(yi)ans = 2 2 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.

  • 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.8585

Now 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)

    interp1 (MATLAB Functions) (6)

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.633

then the population in 1975, obtained by table lookup within the matrix tab, is

  • p = interp1(tab(:,1),tab(:,2),1975)p = 214.8585

Example 4. The following example uses the 'cubic' method to generate the piecewise polynomial form (ppform) of Y, and then evaluates the result using ppval.

  • x = 0:.2:pi; y = sin(x);pp = interp1(x,y,'cubic','pp');xi = 0:.1:pi;yi = ppval(pp,xi);plot(x,y,'ko'), hold on, plot(xi,yi,'r:'), hold off

    interp1 (MATLAB Functions) (7)

Algorithm

The interp1 command is a MATLAB M-file. 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 M-file help for these functions, and the Spline Toolbox.

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.

See Also

interpft, interp2, interp3, interpn, pchip, spline

References

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


int8, int16, int32, int64interp2

© 1994-2005 The MathWorks, Inc.


interp1 (MATLAB Functions) (2024)

FAQs

What does the interp1 function do in MATLAB? ›

Description. vq = interp1( x , v , xq ) returns interpolated values of a 1-D function at specific query points using linear interpolation. Vector x contains the sample points, and v contains the corresponding values, v(x). Vector xq contains the coordinates of the query points.

What is the difference between interp1 and spline in MATLAB? ›

You also can perform spline interpolation using the interp1 function with the command interp1(x,y,xq,'spline') . While spline performs interpolation on rows of an input matrix, interp1 performs interpolation on columns of an input matrix.

Why does interp1 return NaN? ›

If the time at which we want an interpolated value is not within the range of times in the input time series, then interp1 will return NaN.

How to solve interpolation in MATLAB? ›

Description
  1. example. ...
  2. Vq = interpn( V , Xq1,Xq2,...,Xqn ) assumes a default grid of sample points. ...
  3. Vq = interpn( V ) returns the interpolated values on a refined grid formed by dividing the interval between sample values once in each dimension.
  4. example.

How does interp1d work? ›

The function interp1d() is used to interpolate a distribution with 1 variable. It takes x and y points and returns a callable function that can be called with new x and returns corresponding y .

What is an example of interpolation? ›

Interpolation definition says that interpolation is to estimate the value of a point between two given points in a data set. For example, if a child's height was measured at age 5 and age 6, interpolation could be used to estimate the child's height at age 5.5.

Why is spline better? ›

In interpolating problems, spline interpolation is often preferred to polynomial interpolation because it yields similar results, even when using low degree polynomials, while avoiding Runge's phenomenon for higher degrees.

What are the advantages of spline interpolation? ›

Spline interpolation is preferred over polynomial interpolation because the interpolation error can be made small even when using low degree polynomials for the spline. Spline interpolation avoids the problem of Runge's phenomenon, which occurs when the interpolating uses high degree polynomials.

What is the use of spline function in MATLAB? ›

Splines can be used to smooth noisy data and perform interpolation. For a simple example showing how to use splines to perform interpolation, see Cubic Spline Interpolation. Using the Curve Fitter app or the fit function, you can fit cubic spline interpolants, smoothing splines, and thin-plate splines.

Does interp1 extrapolate? ›

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.

Why is MATLAB giving me NaN? ›

It is not defined, so it must be a function that you have kept secret. A NaN results when one of several indeterminate things happens. For example 0/0, inf/inf, inf-inf, etc.

Why does NaN == NaN always return false? ›

When NaN is one of the operands of any relational comparison ( > , < , >= , <= ), the result is always false . NaN compares unequal (via == , != , === , and !== ) to any other value — including to another NaN value.

Which MATLAB function is used for interpolation? ›

1-D and Gridded Interpolation
interp11-D data interpolation (table lookup)
interp2Interpolation for 2-D gridded data in meshgrid format
interp3Interpolation for 3-D gridded data in meshgrid format
interpnInterpolation for 1-D, 2-D, 3-D, and N-D gridded data in ndgrid format
griddedInterpolantGridded data interpolation
8 more rows

What is the easiest method for solving interpolation? ›

One of the simplest methods is linear interpolation (sometimes known as lerp). Consider the above example of estimating f(2.5). Since 2.5 is midway between 2 and 3, it is reasonable to take f(2.5) midway between f(2) = 0.9093 and f(3) = 0.1411, which yields 0.5252.

How do you interpolate correctly? ›

How to interpolate
  1. Identify your data. Use a table to list your data. ...
  2. Create a line of best fit. After using the values to plot a graph, you can draw a line of best fit. ...
  3. Determine your value for interpolation. ...
  4. Use the linear interpolation equation. ...
  5. Solve the equation.
Sep 30, 2022

What does the vectorize function do in MATLAB? ›

Using Vectorization

Appearance: Vectorized mathematical code appears more like the mathematical expressions found in textbooks, making the code easier to understand. Less Error Prone: Without loops, vectorized code is often shorter. Fewer lines of code mean fewer opportunities to introduce programming errors.

What does the function function do in MATLAB? ›

MATLAB function functions evaluate mathematical expressions over a range of values. They are called function functions because they are functions that accept a function handle (a pointer to a function) as an input. Each of these functions expects that your objective function has a specific number of input variables.

How to use interp3 in MATLAB? ›

interp3 (MATLAB Function Reference) VI = interp3(X,Y,Z,V,XI,YI,ZI) interpolates to find VI , the values of the underlying three-dimensional function V at the points in matrices XI , YI and ZI . Matrices X , Y and Z specify the points at which the data V is given. Out of range values are returned as NaN .

What is the function of iterator in MATLAB? ›

An iterator subsystem runs one or more times at the current time step when enabled by a control block. A control block implements control logic similar to that expressed by programming language loop constructs such as while or for .

Top Articles
Hollisterco.com Coupon Codes for August 2024 (15% discount)
Www Dinar Chronicles
Victor Spizzirri Linkedin
Safety Jackpot Login
Craigslist Free En Dallas Tx
Devon Lannigan Obituary
Ixl Elmoreco.com
Gabrielle Abbate Obituary
Bros Movie Wiki
Buying risk?
Koop hier ‘verloren pakketten’, een nieuwe Italiaanse zaak en dit wil je ook even weten - indebuurt Utrecht
FAQ: Pressure-Treated Wood
Parent Resources - Padua Franciscan High School
Plan Z - Nazi Shipbuilding Plans
Lawson Uhs
Halo Worth Animal Jam
Ge-Tracker Bond
Lola Bunny R34 Gif
Exl8000 Generator Battery
Engineering Beauties Chapter 1
Avatar: The Way Of Water Showtimes Near Maya Pittsburg Cinemas
Publix Near 12401 International Drive
Goodwill Of Central Iowa Outlet Des Moines Photos
Great ATV Riding Tips for Beginners
Aes Salt Lake City Showdown
Penn State Service Management
*!Good Night (2024) 𝙵ull𝙼ovie Downl𝚘ad Fr𝚎e 1080𝚙, 720𝚙, 480𝚙 H𝙳 HI𝙽DI Dub𝚋ed Fil𝙼yz𝚒lla Isaidub
Darktide Terrifying Barrage
Evil Dead Rise - Everything You Need To Know
Los Amigos Taquería Kalona Menu
Mydocbill.com/Mr
Boone County Sheriff 700 Report
Pensacola Cars Craigslist
Barber Gym Quantico Hours
Craigslist Tulsa Ok Farm And Garden
World Social Protection Report 2024-26: Universal social protection for climate action and a just transition
2023 Fantasy Football Draft Guide: Rankings, cheat sheets and analysis
Anhedönia Last Name Origin
Login
Costco The Dalles Or
Frequently Asked Questions
Vci Classified Paducah
bot .com Project by super soph
Nurses May Be Entitled to Overtime Despite Yearly Salary
Mail2World Sign Up
Fresno Craglist
Msatlantathickdream
Maurices Thanks Crossword Clue
Taterz Salad
Philasd Zimbra
Leslie's Pool Supply Redding California
Latest Posts
Article information

Author: Velia Krajcik

Last Updated:

Views: 5253

Rating: 4.3 / 5 (54 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Velia Krajcik

Birthday: 1996-07-27

Address: 520 Balistreri Mount, South Armand, OR 60528

Phone: +466880739437

Job: Future Retail Associate

Hobby: Polo, Scouting, Worldbuilding, Cosplaying, Photography, Rowing, Nordic skating

Introduction: My name is Velia Krajcik, I am a handsome, clean, lucky, gleaming, magnificent, proud, glorious person who loves writing and wants to share my knowledge and understanding with you.