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

1-D data interpolation (table lookup)

Since R2024a

collapse all in page

Syntax

vq = fixed.interp1(x,v,xq)

vq = fixed.interp1(v,xq)

vq = fixed.interp1(___,method)

vq = fixed.interp1(___,method,extrapval)

Description

example

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

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

vq = fixed.interp1(v,xq) returns interpolated 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 the absolute distances between points.

vq = fixed.interp1(___,method) specifies an alternative interpolation method: "linear", "nearest", "previous", or "next". The default method is "linear".

vq = fixed.interp1(___,method,extrapval) specifies extrapval, a scalar value that is assigned to all queries that lie outside the domain of the sample points.

Examples

collapse all

Implement 1-D Fixed-Point Lookup Tables Using Interpolation

Open Live Script

This example shows how to implement a one-dimensional fixed-point lookup table using fixed.interp1.

Run the example multiple times to see the approximation over different query points.

Create Lookup Table for Function

Define a function f(x) to replace with a lookup table approximation.

clearvarsf = @(x) exp(x);

Define breakpoints x for the lookup table. Use the following values, which were computed to estimate exp(x) by the Lookup Table Optimizer and targeted 16-bit fixed-point types and on-curve table values.

x = [-11, -6.80029296875, -5.49609375, -4.708984375, -4.1484375, -3.70849609375, ... -3.3466796875, -3.04150390625, -2.7763671875, -2.54150390625, -2.33251953125, ... -2.142578125, -1.96875, -1.8095703125, -1.66259765625, -1.525390625, -1.3974609375, ... -1.27685546875, -1.16357421875, -1.05712890625, -0.95556640625, -0.85791015625, ... -0.76611328125, -0.677734375, -0.5927734375, -0.51171875, -0.43359375, -0.35791015625, ... -0.28515625, -0.21533203125, -0.1484375, -0.08349609375, -0.0205078125, 0];

Generate on-curve table values v corresponding to the breakpoints.

v = f(x);

Plot the table values and notice that the breakpoints x are not linearly spaced.

plot(x,v,'o-')

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

Query Lookup Table

Choose a random query point xq in the range of x.

xq = fixed.example.realUniformRandomArray(x(1),x(end),1);

Cast the inputs to 16-bit fixed-point.

x = fi(x);v = fi(v);xq = fi(xq);

The fixed.interp1 function computes vq, the lookup table approximation of f(xq). That is, vqf(xq).

vq = fixed.interp1(x,v,xq)
vq = 0.1307 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 14

Compare Lookup Approximation to Actual Function Value

Compare vq to the actual function evaluation f(xq).

vq_expected = f(double(xq))
vq_expected = 0.1303
err = double(vq) - vq_expected
err = 4.5947e-04

Plot f(x).

clf;plot(x,v)xlabel('x')ylabel('v')hold on

Plot vq, the lookup table approximation of f(xq), using a red stem plot.

stem(xq,vq,'Filled','red')legend('f(x)','vq = Fixed-point lookup-table approximation of f(xq)','location','best')

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

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 strictly monotonically increasing. The length of x must conform to one of the following requirements:

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

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

The inputs x, v, and xq must be the same data type: fi, half, single, or double. When using fi data, you can use the shortened function name interp1.

Example: fi(1:10,0,8,0)

Example: half(1:10)

Data Types: fi | single | double

vSample values
vector | matrix | array

Sample values, specified as a vector, matrix, or array of real or 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 fixed.interp1 interpolates the real and imaginary parts separately.

The inputs x, v, and xq must be the same data type: fi, half, single, or double. When using fi data, you can use the shortened function name interp1.

Example: fi(rand(10,1),0,12,8)

Example: half(rand(10,1))

Data Types: fi | single | double
Complex Number Support: Yes

xqQuery points
scalar | vector | matrix | array

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

The inputs x, v, and xq must be the same data type: fi, half, single, or double. When using fi data, you can use the shortened function name interp1.

Example: fi(5,0,12,8)

Example: half(5)

Example: half(1:0.05:10)

Example: half((1:0.05:10)')

Example: half([0 1 2 7.5 10])

Data Types: fi | single | double

methodInterpolation method
"linear" (default) | "nearest" | "next" | "previous"

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 method 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"

extrapvalFunction value outside the domain of x
scalar

Function value outside the domain of x, specified as a real or complex scalar. fixed.interp1 returns this constant value for all points outside the domain of x. If the scalar value is nonzero and outside the range of the sample values v, then this value is set to the minimum or maximum value of v, whichever is closer.

The data type of extrapval must be the same as x, v, and xq.

The default behavior with fi input data is to return 0 for query points outside the domain. The default behavior with half, single, or double input data is to return NaN for query points outside the domain.

Example: fi(5,0,12,8)

Example: half(5)

Data Types: fi | single | double

Note

The default behavior of the interp1 function is to return NaN when a query point is outside the domain. The fixed.interp1 function with fi input data is not consistent with this behavior because fi casts NaN to 0.

Output Arguments

collapse all

vq — Interpolated values
scalar | vector | matrix | array

Interpolated values, returned as a scalar, vector, matrix, or array. The size of vq depends on the shape of v and xq. The data type of vq is the same as that of the sample values v.

Shape of vShape of 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) = [50 30].
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) = [500 3].
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 3 7 5 6].

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

HDL Code Generation
Generate VHDL, Verilog and SystemVerilog code for FPGA and ASIC designs using HDL Coder™.

Version History

Introduced in R2024a

See Also

fixed.interp2 | fixed.interp3 | fixed.interpn | interp1

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) (3)

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) (2024)

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

How do you interpolate data tables? ›

Here's how to use linear interpolation to calculate a value within a data set:
  1. Organize your data. ...
  2. Consider creating a graph. ...
  3. Select your two points. ...
  4. Enter values into the interpolation equation. ...
  5. Solve for the missing variable.
Oct 16, 2023

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.

How does a lookup table work? ›

A lookup table is an array of data that maps input values to output values, thereby approximating a mathematical function. Given a set of input values, a lookup operation retrieves the corresponding output values from the table.

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.

How to interpolate table data in Excel? ›

Input the formula

Click on your cell labeled "interpolated value." Once you click on this cell, navigate to the "formula bar" above the cell columns. In the formula bar, write the formula y = y1 + (x - x1) ⨯ (y2 - y1) / (x2 - x1).

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

How do I find a lookup table? ›

First, choose an empty cell → select the “Formulas” tab → go to the “Function Library” group → click the “Lookup & Reference” option drop-down → select the “VLOOKUP” function, as shown below. Similarly, we can insert the LOOKUP function, as we can see the function available above the VLOOKUP function.

What is a 2D lookup table? ›

The two-dimensional Lookup Table block performs a lookup in a user-defined table for the value of a single dependent variable (the block output) using two fields as indexes (the independent variables, block inputs).

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

References

Top Articles
Latest Posts
Recommended Articles
Article information

Author: Duane Harber

Last Updated:

Views: 6020

Rating: 4 / 5 (71 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Duane Harber

Birthday: 1999-10-17

Address: Apt. 404 9899 Magnolia Roads, Port Royceville, ID 78186

Phone: +186911129794335

Job: Human Hospitality Planner

Hobby: Listening to music, Orienteering, Knapping, Dance, Mountain biking, Fishing, Pottery

Introduction: My name is Duane Harber, I am a modern, clever, handsome, fair, agreeable, inexpensive, beautiful person who loves writing and wants to share my knowledge and understanding with you.