1-D data interpolation (table lookup) (2025)

Table of Contents
Syntax Description Examples Interpolation of Coarsely Sampled Sine Function Interpolation Without Specifying Points Interpolation of Complex Values Interpolation of Dates and Times Extrapolation Using Two Different Methods Designate Constant Value for All Queries Outside the Domain of x Interpolate Multiple Sets of Data in One Pass Input Arguments x — Sample points vector v — Sample values vector | matrix | array xq — Query points scalar | vector | matrix | array method — Interpolation method 'linear' (default) | 'nearest' | 'next' | 'previous' | 'pchip' | 'cubic' | 'v5cubic' | 'makima' | 'spline' extrapolation — Extrapolation strategy 'extrap' | scalar value Output Arguments vq — Interpolated values scalar | vector | matrix | array pp — Piecewise polynomial structure More About Akima and Spline Interpolation References Extended Capabilities C/C++ Code Generation Generate C and C++ code using MATLAB® Coder™. GPU Code Generation Generate CUDA® code for NVIDIA® GPUs using GPU Coder™. Thread-Based Environment Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool. GPU Arrays Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™. Distributed Arrays Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™. Version History R2020b: 'cubic' method of interp1 performs cubic convolution See Also MATLAB Command Americas Europe Asia Pacific FAQs

1-D data interpolation (table lookup)

collapse all in page

Syntax

vq = interp1(x,v,xq)

vq = interp1(x,v,xq,method)

vq = interp1(x,v,xq,method,extrapolation)

vq = interp1(v,xq)

vq = interp1(v,xq,method)

vq = interp1(v,xq,method,extrapolation)

pp = interp1(x,v,method,'pp')

Description

example

vq = interp1(x,v,xq) returnsinterpolated values of a 1-D function at specific query points usinglinear interpolation. Vector x contains the samplepoints, and v contains the corresponding values, v(x).Vector xq contains the coordinates of the querypoints.

If you have multiple sets of data that are sampled at the samepoint coordinates, then you can pass v as an array.Each column of array v contains a different setof 1-D sample values.

example

vq = interp1(x,v,xq,method) specifies an alternative interpolation method: 'linear', 'nearest', 'next', 'previous', 'pchip', 'cubic', 'v5cubic', 'makima', or 'spline'. The default method is 'linear'.

example

vq = interp1(x,v,xq,method,extrapolation) specifiesa strategy for evaluating points that lie outside the domain of x.Set extrapolation to 'extrap' whenyou want to use the method algorithm for extrapolation.Alternatively, you can specify a scalar value, in which case, interp1 returnsthat value for all points outside the domain of x.

example

vq = interp1(v,xq) returnsinterpolated values and assumes a default set of sample point coordinates.The default points are the sequence of numbers from 1 to n,where n depends on the shape of v:

  • When v is a vector, the default points are 1:length(v).

  • When v is an array, the default points are 1:size(v,1).

Use this syntax when you are not concerned about theabsolute distances between points.

vq = interp1(v,xq,method) specifiesany of the alternative interpolation methods and uses the defaultsample points.

vq = interp1(v,xq,method,extrapolation) specifiesan extrapolation strategy and uses the default sample points.

pp = interp1(x,v,method,'pp') returns the piecewise polynomial form of v(x) using the method algorithm.

Note

This syntax is not recommended. Use griddedInterpolant instead.

Examples

collapse all

Interpolation of Coarsely Sampled Sine Function

Open Live Script

Define the sample points, x, and corresponding sample values, v.

x = 0:pi/4:2*pi; v = sin(x);

Define the query points to be a finer sampling over the range of x.

xq = 0:pi/16:2*pi;

Interpolate the function at the query points and plot the result.

figurevq1 = interp1(x,v,xq);plot(x,v,'o',xq,vq1,':.');xlim([0 2*pi]);title('(Default) Linear Interpolation');

1-D data interpolation (table lookup) (1)

Now evaluate v at the same points using the 'spline' method.

figurevq2 = interp1(x,v,xq,'spline');plot(x,v,'o',xq,vq2,':.');xlim([0 2*pi]);title('Spline Interpolation');

1-D data interpolation (table lookup) (2)

Interpolation Without Specifying Points

Open Live Script

Define a set of function values.

v = [0 1.41 2 1.41 0 -1.41 -2 -1.41 0];

Define a set of query points that fall between the default points, 1:9. In this case, the default points are 1:9 because v contains 9 values.

xq = 1.5:8.5;

Evaluate v at xq.

vq = interp1(v,xq);

Plot the result.

figureplot((1:9),v,'o',xq,vq,'*');legend('v','vq');

1-D data interpolation (table lookup) (3)

Interpolation of Complex Values

Open Live Script

Define a set of sample points.

x = 1:10;

Define the values of the function, v(x)=5x+x2i, at the sample points.

v = (5*x)+(x.^2*1i);

Define the query points to be a finer sampling over the range of x.

xq = 1:0.25:10;

Interpolate v at the query points.

vq = interp1(x,v,xq);

Plot the real part of the result in red and the imaginary part in blue.

figureplot(x,real(v),'*r',xq,real(vq),'-r');hold onplot(x,imag(v),'*b',xq,imag(vq),'-b');

1-D data interpolation (table lookup) (4)

Interpolation of Dates and Times

Open Live Script

Interpolate time-stamped data points.

Consider a data set containing temperature readings that are measured every four hours. Create a table with one day's worth of data and plot the data.

x = (datetime(2016,1,1):hours(4):datetime(2016,1,2))';x.Format = 'MMM dd, HH:mm';T = [31 25 24 41 43 33 31]';WeatherData = table(x,T,'VariableNames',{'Time','Temperature'})
WeatherData=7×2 table Time Temperature _____________ ___________ Jan 01, 00:00 31 Jan 01, 04:00 25 Jan 01, 08:00 24 Jan 01, 12:00 41 Jan 01, 16:00 43 Jan 01, 20:00 33 Jan 02, 00:00 31 
plot(WeatherData.Time, WeatherData.Temperature, 'o')

1-D data interpolation (table lookup) (5)

Interpolate the data set to predict the temperature reading during each minute of the day. Since the data is periodic, use the 'spline' interpolation method.

xq = (datetime(2016,1,1):minutes(1):datetime(2016,1,2))';V = interp1(WeatherData.Time, WeatherData.Temperature, xq, 'spline');

Plot the interpolated points.

hold onplot(xq,V,'r')

1-D data interpolation (table lookup) (6)

Extrapolation Using Two Different Methods

Open Live Script

Define the sample points, x, and corresponding sample values, v.

x = [1 2 3 4 5];v = [12 16 31 10 6];

Specify the query points, xq, that extend beyond the domain of x.

xq = [0 0.5 1.5 5.5 6];

Evaluate v at xq using the 'pchip' method.

vq1 = interp1(x,v,xq,'pchip')
vq1 = 1×5 19.3684 13.6316 13.2105 7.4800 12.5600

Next, evaluate v at xq using the 'linear' method.

vq2 = interp1(x,v,xq,'linear')
vq2 = 1×5 NaN NaN 14 NaN NaN

Now, use the 'linear' method with the 'extrap' option.

vq3 = interp1(x,v,xq,'linear','extrap')

'pchip' extrapolates by default, but 'linear' does not.

Designate Constant Value for All Queries Outside the Domain of x

Open Live Script

Define the sample points, x, and corresponding sample values, v.

x = [-3 -2 -1 0 1 2 3];v = 3*x.^2;

Specify the query points, xq, that extend beyond the domain of x.

xq = [-4 -2.5 -0.5 0.5 2.5 4];

Now evaluate v at xq using the 'pchip' method and assign any values outside the domain of x to the value, 27.

vq = interp1(x,v,xq,'pchip',27)
vq = 1×6 27.0000 18.6562 0.9375 0.9375 18.6562 27.0000

Interpolate Multiple Sets of Data in One Pass

Open Live Script

Define the sample points.

x = (-5:5)';

Sample three different parabolic functions at the points defined in x.

v1 = x.^2;v2 = 2*x.^2 + 2;v3 = 3*x.^2 + 4;

Create matrix v, whose columns are the vectors, v1, v2, and v3.

v = [v1 v2 v3];

Define a set of query points, xq, to be a finer sampling over the range of x.

xq = -5:0.1:5;

Evaluate all three functions at xq and plot the results.

vq = interp1(x,v,xq,'pchip');figureplot(x,v,'o',xq,vq);h = gca;h.XTick = -5:5;

1-D data interpolation (table lookup) (7)

The circles in the plot represent v, and the solid lines represent vq.

Input Arguments

collapse all

xSample points
vector

Sample points, specified as a row or column vector of real numbers.The values in x must be distinct. The length of x mustconform to one of the following requirements:

  • If v is a vector, then length(x) mustequal length(v).

  • If v is an array, then length(x) mustequal size(v,1).

Example: [1 2 3 4 5 6 7 8 9 10]

Example: 1:10

Example: [37 11 15 19 23 27 31]'

Data Types: single | double | duration | datetime

vSample values
vector | matrix | array

Sample values, specified as a vector, matrix, or array of realor complex numbers. If v is a matrix or an array,then each column contains a separate set of 1-D values.

If v contains complex numbers, then interp1 interpolatesthe real and imaginary parts separately.

Example: rand(1,10)

Example: rand(10,1)

Example: rand(10,3)

Data Types: single | double | duration | datetime
Complex Number Support: Yes

xqQuery points
scalar | vector | matrix | array

Query points, specified as a scalar, vector, matrix, or arrayof real numbers.

Example: 5

Example: 1:0.05:10

Example: (1:0.05:10)'

Example: [0 1 2 7.5 10]

Data Types: single | double | duration | datetime

methodInterpolation method
'linear' (default) | 'nearest' | 'next' | 'previous' | 'pchip' | 'cubic' | 'v5cubic' | 'makima' | 'spline'

Interpolation method, specified as one of the options in this table.

Method

Description

Continuity

Comments

'linear'

Linear interpolation. The interpolated value at a query point is based on linear interpolation of the values at neighboring grid points in each respective dimension. This is the default interpolation method.

C0

  • Requires at least 2 points

  • Requires more memory and computation time than nearest neighbor

'nearest'

Nearest neighbor interpolation. The interpolated value at a query point is the value at the nearest sample grid point.

Discontinuous

  • Requires at least 2 points

  • Modest memory requirements

  • Fastest computation time

'next'

Next neighbor interpolation. The interpolated value at a query point is the value at the next sample grid point.

Discontinuous

  • Requires at least 2 points

  • Same memory requirements and computation time as 'nearest'

'previous'

Previous neighbor interpolation. The interpolated value at a query point is the value at the previous sample grid point.

Discontinuous

  • Requires at least 2 points

  • Same memory requirements and computation time as 'nearest'

'pchip'

Shape-preserving piecewise cubic interpolation. The interpolated value at a query point is based on a shape-preserving piecewise cubic interpolation of the values at neighboring grid points.

C1

  • Requires at least 4 points

  • Requires more memory and computation time than 'linear'

'cubic'

Cubic convolution used in MATLAB® 5.

C1

  • Requires at least 3 points

  • Points must be uniformly spaced

  • This method falls back to 'spline' interpolation for irregularly-spaced data

  • Similar memory requirements and computation time as 'pchip'

'v5cubic'

Same as 'cubic'.

C1

'makima'

Modified Akima cubic Hermite interpolation. The interpolated value at a query point is based on a piecewise function of polynomials with degree at most three. The Akima formula is modified to avoid overshoots.

C1

  • Requires at least 2 points

  • Produces fewer undulations than 'spline', but does not flatten as aggressively as 'pchip'

  • Computation is more expensive than 'pchip', but typically less than 'spline'

  • Memory requirements are similar to those of 'spline'

'spline'

Spline interpolation using not-a-knot end conditions. The interpolated value at a query point is based on a cubic interpolation of the values at neighboring grid points in each respective dimension.

C2

  • Requires at least 4 points

  • Requires more memory and computation time than 'pchip'

extrapolationExtrapolation strategy
'extrap' | scalar value

Extrapolation strategy, specified as 'extrap' ora real scalar value.

  • Specify 'extrap' when you want interp1 toevaluate points outside the domain using the same method it uses forinterpolation.

  • Specify a scalar value when you want interp1 toreturn a specific constant value for points outside the domain.

The default behavior depends on the input arguments:

  • If you specify the 'pchip', 'spline', or 'makima' interpolation methods, then the default behavior is 'extrap'.

  • All other interpolation methods return NaN bydefault for query points outside the domain.

Example: 'extrap'

Example: 5

Data Types: char | string | single | double

Output Arguments

collapse all

vq — Interpolated values
scalar | vector | matrix | array

Interpolated values, returned as a scalar, vector, matrix, orarray. The size of vq depends on the shape of v and xq.

Shape of vShapeof xqSize of VqExample
VectorVectorsize(xq)If size(v) = [1 100]
and size(xq)= [1 500],
then size(vq) = [1 500].
VectorMatrix
or N-D Array
size(xq)If size(v) = [1 100]
and size(xq)= [50 30],
then size(vq) = [5030].
Matrix
or N-D Array
Vector[length(xq) size(v,2),...,size(v,n)]If size(v) = [100 3]
and size(xq)= [1 500],
then size(vq) = [5003].
Matrix
or N-D Array
Matrix
or N-D Array
[size(xq,1),...,size(xq,n),... size(v,2),...,size(v,m)]If size(v) = [4 5 6]
and size(xq)= [2 3 7],
then size(vq) = [2 37 5 6].

pp — Piecewise polynomial
structure

Piecewise polynomial, returned as a structure that you can passto the ppval function for evaluation.

More About

collapse all

Akima and Spline Interpolation

The Akima algorithm for one-dimensional interpolation, described in [1] and [2], performs cubic interpolation to produce piecewise polynomials with continuous first-order derivatives (C1). The algorithm preserves the slope and avoids undulations in flat regions. A flat region occurs whenever there are three or more consecutive collinear points, which the algorithm connects with a straight line. To ensure that the region between two data points is flat, insert an additional data point between those two points.

When two flat regions with different slopes meet, the modification made to the original Akima algorithm gives more weight to the side where the slope is closer to zero. This modification gives priority to the side that is closer to horizontal, which is more intuitive and avoids the overshoot. (The original Akima algorithm gives equal weights to the points on both sides, thus evenly dividing the undulation.)

The spline algorithm, on the other hand, performs cubic interpolation to produce piecewise polynomials with continuous second-order derivatives (C2). The result is comparable to a regular polynomial interpolation, but is less susceptible to heavy oscillation between data points for high degrees. Still, this method can be susceptible to overshoots and oscillations between data points.

Compared to the spline algorithm, the Akima algorithm produces fewer undulations and is better suited to deal with quick changes between flat regions. This difference is illustrated below using test data that connects multiple flat regions.

1-D data interpolation (table lookup) (8)

References

[1] Akima, Hiroshi. "A new method of interpolation and smooth curve fitting based on local procedures." Journal of the ACM (JACM) , 17.4, 1970, pp. 589-602.

[2] Akima, Hiroshi. "A method of bivariate interpolation and smooth surface fitting based on local procedures." Communications of the ACM , 17.1, 1974, pp. 18-20.

Extended Capabilities

Version History

Introduced before R2006a

expand all

See Also

interp2 | interp3 | interpn | griddedInterpolant

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

1-D data interpolation (table lookup) (9)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

1-D data interpolation (table lookup) (2025)

FAQs

What is a 1D lookup table? ›

1D Lookup table generates an output signal by interpolating based on a given data set and input value. The Input values x property must be a strictly increasing or decreasing array. It supports equidistant and non-equidistant distributions of table indexes (Input values x):

What is the formula for 1 dimensional interpolation? ›

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.

How to calculate lookup table in Matlab? ›

Lookup table blocks use arrays of data to map input values to output values, approximating mathematical functions. To approximate a function in N variables, use the n-D Lookup Table block: To manage the lookup tables in your environment, consider using the Lookup Table Editor.

What is the difference between VLOOKUP and lookup table? ›

The LOOKUP function allows a user to search for a piece of data in a row or column and return a corresponding piece of data in another row or column. The VLOOKUP function is similar but only allows a user to search vertically in a row and only returns data in a left-to-right procedure.

What is the difference between lookup table and dimension table? ›

Dimension tables, also known as lookup or reference tables, contain the relatively static data in the data warehouse. Dimension tables store the information you normally use to contain queries. Dimension tables are usually textual and descriptive and you can use them as the row headers of the result set.

Does vlookup interpolate? ›

A lookup by itself won't interpolate any data, if an exact match is not wanted, both VLOOKUP and MATCH can return the largest value that is less than or equal to lookup_value. For that kind of match, the column that the functions look in for a match must be sorted.

What is the best data interpolation method? ›

Radial Basis Function interpolation is a diverse group of data interpolation methods. In terms of the ability to fit your data and produce a smooth surface, the Multiquadric method is considered by many to be the best.

What is the best way to interpolate data? ›

Linear interpolation is the most straightforward and commonly used interpolation method. It comes naturally when we have two points, we connect them with a straight line to fill out the missing information in between. By doing so, we made our assumption that the points on the line represent the unobserved values.

What is the simplest method of interpolation? ›

One of the simplest methods, linear interpolation, requires knowledge of two points and the constant rate of change between them. With this information, you may interpolate values anywhere between those two points.

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.

What is interpolate 1D array? ›

Interpolate 1D Array. Calculates a decimal y-value from an array of numbers or points at a specified fractional index or x-value using linear interpolation.

What is the lookup table method? ›

A lookup table is an array of data that maps input values to output values, thereby approximating a mathematical function.

What is lookup data table? ›

Lookup tables — similar to cross-reference tables — allow you to easily look up frequently used data in a recipe. Lookup tables are structured with rows and columns. You can look up entries in a lookup table by matching data in one or more columns.

What is a 1D figure? ›

One dimensional (1-D) figures are lines that lie in one plane and have length in at least one direction. When we check a thermometer to see what the temperature is, it is only measuring data on one plane— temperature.

What do you mean by lookup table? ›

An array or matrix of data that contains items that are searched. Lookup tables may be arranged as key-value pairs, where the keys are the data items being searched (looked up) and the values are either the actual data or pointers to where the data are located.

What is a 1D function? ›

One-dimensional functions take a single input value and output a single evaluation of the input. They may be the simplest type of test function to use when studying function optimization.

What is VLOOKUP table used for? ›

Answer: In Excel, use the function, VLookup, to lookup a value in one place and insert it into another.

Top Articles
Latest Posts
Recommended Articles
Article information

Author: Tuan Roob DDS

Last Updated:

Views: 5509

Rating: 4.1 / 5 (62 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Tuan Roob DDS

Birthday: 1999-11-20

Address: Suite 592 642 Pfannerstill Island, South Keila, LA 74970-3076

Phone: +9617721773649

Job: Marketing Producer

Hobby: Skydiving, Flag Football, Knitting, Running, Lego building, Hunting, Juggling

Introduction: My name is Tuan Roob DDS, I am a friendly, good, energetic, faithful, fantastic, gentle, enchanting person who loves writing and wants to share my knowledge and understanding with you.