Lookup table calculator: 1-D and 2-D, read like Simulink

Paste breakpoints and table data, give an input, and see the output a Simulink 1-D or 2-D Lookup Table block gives with Flat, Nearest or Linear interpolation and Clip or Linear extrapolation. It shows the interval, the fraction and the weights used, sizes the breakpoints for an error you choose, counts the memory and writes the same table as C, MATLAB and Python. Free, runs in your browser.

MathWorks R2026b 1-D / 2-D / n-D Lookup Table and Interpolation Methods docs · Battery (Table-Based) block · Updated 22 Nov 2026

Opens on the five-point x³ table. Simulink's own default block is tanh on −5:5; pick it to see how far a coarse default is from the real curve.

Output y5.9linear, inside the table
Index k, fraction f3, 0.7zero-based, as Prelookup outputs
Breakpoint spacingevenbinary search: 3 comparisons
Your table-10010-2-1012stored pointsblock outputxy
  • Calculating…
C code
#define N 5
static const float BP[N] = {
    -2.0f, -1.0f, 0.0f, 1.0f, 2.0f
};
static const float TB[N] = {
    -8.0f, -1.0f, 0.0f, 1.0f, 8.0f
};

/* interval k (0..n-2) and fraction f, binary search like the block's default */
static int locate(const float *bp, int n, float u, float *f)
{
    if (u <= bp[0])     { *f = (u - bp[0]) / (bp[1] - bp[0]); return 0; }  /* Linear extrapolation */
    if (u >= bp[n - 1]) { *f = (u - bp[n - 2]) / (bp[n - 1] - bp[n - 2]); return n - 2; }
    int lo = 0, hi = n - 1;
    while (hi - lo > 1) {
        int mid = (lo + hi) / 2;
        if (u < bp[mid]) hi = mid; else lo = mid;
    }
    *f = (u - bp[lo]) / (bp[lo + 1] - bp[lo]);
    return lo;
}

float lut1d(float u)
{
    float f;
    int k = locate(BP, N, u, &f);
    return TB[k] + f * (TB[k + 1] - TB[k]);   /* Linear point-slope */
}
MATLAB code
bp = [-2 -1 0 1 2];
tb = [-8 -1 0 1 8];
u  = 1.7;
y = interp1(bp, tb, u, 'linear', 'extrap');

% The same table as a Simulink.LookupTable object (for the 1-D Lookup Table block)
LUT = Simulink.LookupTable;
LUT.Table.Value = tb;
LUT.Breakpoints(1).Value = bp;
Python code
import numpy as np
from scipy.interpolate import interp1d
bp = np.array([-2,-1,0,1,2])
tb = np.array([-8,-1,0,1,8])
u = 1.7
y = interp1d(bp, tb, fill_value='extrapolate')(u)   # Linear extrapolation
print(y)

How does a lookup table compute its output?

A lookup table stores a function's values at chosen inputs, the breakpoints, and answers any other input from its two neighbours. Simulink's 1-D Lookup Table block does three things on every call: it finds the interval that holds the input (binary search by default), works out the fraction f of the way along it, and applies the interpolation rule. With the default Linear point-slope method:

Take five breakpoints of y = x³, −2 to 2, so the table holds −8, −1, 0, 1, 8. For x = 1.7 the interval is 1 to 2 (k = 3 counting from zero, as the Prelookup block does):

The true value is 4.913, so the table is about 1.0 high. That is not a bug: a straight line from (1, 1) to (2, 8) cannot follow a curve that bends this hard. At x = −1.5 the same table gives −4.5 against a true −3.375. The fix is more breakpoints, and the third tab of the calculator counts how many.

x³ table, five breakpoints, linear interpolation and linear extrapolation, against the true curve-10010-2-1012stored pointsblock outputtrue functionxy

Simulink's own default block makes the same point. A new 1-D Lookup Table opens with breakpoints −5:5 and table data tanh(−5:5). At u = 0.3 it outputs 0.22848, while tanh(0.3) = 0.29131: 21.6% low, because one-unit spacing is far too coarse where tanh bends.

Flat, Nearest or Linear: what does each method return?

Flat returns the stored value at the breakpoint below the input (MathWorks calls this "Use Input Below"). Nearest returns the value at the closest breakpoint, and when the input is exactly halfway, "the breakpoint with the higher index is chosen". Linear point-slope draws the straight line between the two neighbours.

MethodRulex = 1.7x = 1.5
FlatValue at the breakpoint below11
NearestValue at the closest breakpoint; a tie goes to the higher index88
Linear point-slope (default)Straight line between the neighbours5.94.5

Flat and Nearest suit tables whose output really is a step: a gear number, a fault code, a sensor with discrete levels. Linear is the workhorse for anything physical. Linear Lagrange gives the same number as Linear point-slope on a 1-D or 2-D linear table; it is the same straight line written another way.

x³ table read with Nearest: steps, and at x = 1.5 the tie goes to the higher breakpoint-505-2-1012stored pointsblock outputxy

Clip or Linear extrapolation: what happens outside the table?

Linear extrapolation, the block's default, carries the end interval's line past the last breakpoint. Clip "returns the table data corresponding to the end of the breakpoint vector range". At x = 2.5 on the x³ table, Linear gives 8 + 0.5 × 7 = 11.5, Clip gives 8, and the true value is 15.625. Neither is a measurement.

Use Clip for measured maps such as battery voltage or engine torque, where the physics past the last test point is unknown. If an out-of-range input means something has gone wrong, set Diagnostic for out-of-range input to Warning or Error (the default is None). Since R2025a, Assume input is within range replaces the old "remove protection" option. When ticked, the generated code drops the range checks, and MathWorks' advice is: "For safety critical applications, do not select Assume input is within range."

Flat and Nearest in this tool hold the end values outside the table. MathWorks defines Use Input Below as returning the nearest breakpoint's value when there is none below; for inputs above the table with Linear extrapolation selected the documentation does not say, so check that case in your own model.

How does a 2-D lookup table interpolate?

Simulink's 2-D Lookup Table takes u1 as the "first-dimension (row)" input and u2 as the column input. With Linear interpolation it finds the row interval (fraction a) and the column interval (fraction b), interpolates along the columns at both rows, then between the two rows. This is bilinear interpolation. Each corner is weighted by the area of the rectangle opposite it, and the weights always add up to 1:

MathWorks' Battery (Table-Based) block ships an open-circuit voltage table with SOC breakpoints 0, 0.1, 0.25, 0.5, 0.75, 0.9 and 1, and temperatures 278, 293 and 313 K. At SOC 0.6 and 300 K (26.85 °C):

SOC ↓ / T (K) →278293313
03.493.53.51
0.13.553.573.56
0.253.623.633.64
0.53.713.71w 0.393.72w 0.21
0.753.913.93w 0.263.94w 0.14
0.94.074.084.08
14.194.194.19

Flat reads 3.71 V there (the cell at SOC 0.5, 293 K) and Nearest 3.71 V (SOC 0.5, 293 K is also the closest corner). Outside the table, at SOC 1.2 and 330 K, Clip holds 4.19 V while Linear extrapolation gives 4.41 V. Below an empty cell, at SOC −0.1 and 300 K, Linear gives 3.4405 V against Clip's 3.5035 V. That is why measured cell tables are usually clipped: MathWorks' Battery (Table-Based) block itself defaults to holding the end value.

How many breakpoints does a lookup table need?

For linear interpolation the worst error on an interval of width h is at most h² max|f''| / 8, where f'' is the curve's second derivative. Choose the error you can live with, solve for the spacing, and count the points:

Halving the spacing cuts the error by four. The calculator builds each table and finds its real worst error, which always sits just under the target:

FunctionRangeError allowedmax |f''|BreakpointsWorst error found
x³-2 to 20.0112500.00979
sin x0 to π/20.00011570.0000983
eˣ0 to 20.0017.389620.000977
√x1 to 90.00010.251430.0000952

Put extra breakpoints only where the curve bends; uneven spacing is allowed as long as the breakpoints are strictly increasing. Evenly spaced breakpoints have one advantage: the block's Evenly spaced points search reads only the first two breakpoints and computes the index directly, with no search at all. For measured data, estimate max|f''| from second differences of the data, or test a table by reading it back at the measured points.

How much memory does a lookup table take?

A 20 × 20 table in single precision is 20 × 20 × 4 = 1,600 bytes plus 40 × 4 = 160 bytes of breakpoints, 1,760 bytes in all. The 7 × 3 battery table in double is 248 bytes. A 57-point quarter-wave sine stored as int16 with single breakpoints is 114 + 228 = 342 bytes. That is nothing on a PC and noticeable on a controller holding dozens of maps; MathWorks' Lookup Table Optimizer (Fixed-Point Designer) searches for the smallest table and data types that meet an error tolerance.

The same table in C, MATLAB and Python: what changes?

  • C. The generated code is a binary search, a fraction and one interpolation: the same three steps the block performs. It was compiled and run on all 188 test cases of this page and matches them. On a fixed-point target you would store integers and choose power-of-two spacing so the division becomes a shift.
  • MATLAB interp1 returns NaN outside the data for 'linear' unless you pass 'extrap'. For Clip, limit the input with min/max first. For 2-D, interp2(X, Y, V, Xq, Yq) takes the column breakpoints first, so the block's table is interp2(bp2, bp1, T, u2, u1); griddedInterpolant({bp1, bp2}, T) keeps the block's row-first order.
  • NumPy np.interp holds the end values outside the data, which is Clip. SciPy's interp1d with fill_value='extrapolate' is Linear extrapolation, and RegularGridInterpolator with fill_value=None extrapolates a 2-D table.

What this calculator does not model

  • Cubic spline and Akima spline. MathWorks says Cubic spline "fits a cubic spline to the adjacent breakpoints" but does not state its end conditions, so this tool does not guess them. For spline-shaped curves between data points, the interpolation calculator covers MATLAB's spline, pchip and makima.
  • Fixed-point arithmetic. Integer table types change the result by rounding (the block's default integer rounding mode is Simplest). The memory figures above are exact; the outputs are computed in double precision.
  • More than two dimensions, Prelookup sharing, Direct Lookup and Lookup Table Dynamic. The index and fraction shown are what a Prelookup block would output for the same breakpoints. With Clip and an input at or above the last breakpoint, the block by default reports the last interval with fraction 1; Use last table value for inputs at or above last breakpoint reports the last breakpoint with fraction 0 instead. The output value is the same.
  • Your model's settings. Check the block's own dialog: a table entered with the wrong orientation (columns where rows belong) gives a plausible but wrong answer, and the calculator cannot know which you meant.
Learn MATLAB and Simulink

Lookup tables run through every engine, battery and motor model in Simulink. Skill-Lync's MATLAB and Simulink courses build them from the ground up, and the EV battery course uses table-based cell models in its projects.

Frequently asked questions

How does a lookup table calculate its output?

It finds the two breakpoints either side of the input, works out how far along that interval the input sits (the fraction f, 0 to 1), and interpolates between the two stored values: y = yk + f (yk+1 − yk). On a five-point x³ table, x = 1.7 lies 0.7 of the way from 1 to 2, so the output is 1 + 0.7 × 7 = 5.9. The true value is 4.913.

What is the difference between Flat, Nearest and Linear interpolation in Simulink?

Flat returns the table value at the breakpoint below the input, Nearest the value at the closest breakpoint, and Linear point-slope (the default) a straight line between the two neighbours. At x = 1.7 on the x³ table they give 1, 8 and 5.9. When the input is exactly halfway, Nearest takes the breakpoint with the higher index.

Should I use Clip or Linear extrapolation?

Use Clip for measured maps (battery voltage, engine torque), where nobody knows what happens past the last test point: it holds the end value. Linear, the block's default, carries the last interval's slope on. At x = 2.5 on the x³ table, Linear gives 11.5, Clip 8, and the true value is 15.625.

How does a 2-D lookup table interpolate?

Bilinearly: along the second input at the two bracketing rows, then between those two results along the first input. Each of the four corner values is weighted by the area of the rectangle opposite it, and the weights add up to 1. MathWorks' default Battery (Table-Based) OCV table gives 3.8015 V at SOC 0.6 and 300 K.

How many breakpoints does a lookup table need?

For linear interpolation with even spacing h, the error is at most h² max|f''| / 8. Pick the error you can accept, solve for h, then count. A table of x³ on −2 to 2 needs 50 breakpoints to stay within 0.01 (worst error found 0.00979); a quarter-wave sine needs 57 for 0.0001.

Why does interp2 give a different answer from my Simulink 2-D Lookup Table?

Usually the argument order. Simulink's u1 picks the rows and u2 the columns, but interp2(X, Y, V, Xq, Yq) takes the column breakpoints first: interp2(bp2, bp1, T, u2, u1). griddedInterpolant({bp1, bp2}, T) uses the same row-first order as the block. Outside the table, interp2 returns NaN where the block extrapolates or clips.

Related on Skill-Lync

Sources

  • MathWorks, 1-D Lookup Table, 2-D Lookup Table and n-D Lookup Table block reference pages, R2026b, read 22 Nov 2026: interpolation methods (Linear point-slope default), extrapolation methods (Linear default, Clip), spline pairing rule, index search methods (binary default), Diagnostic for out-of-range input, Assume input is within range (since R2025a), u1 = row input, default table tanh(−5:5) on −5:5.
  • MathWorks, "Interpolation Methods" (Simulink user guide), read 22 Nov 2026: Flat = Use Input Below; Nearest tie rule ("the breakpoint with the higher index is chosen"); Clip definition; Akima and Cubic spline descriptions.
  • MathWorks, "About Lookup Table Blocks": breakpoints must be "strictly monotonically increasing".
  • MathWorks, Battery (Table-Based) block: default SOC and temperature breakpoints and open-circuit voltage table (read 17 Nov 2026 for the companion post).
  • MathWorks interp1 / interp2 / griddedInterpolant documentation; NumPy numpy.interp; SciPy interp1d and RegularGridInterpolator.
  • Skill-Lync, scripts/verify/lookup-table.py: 202 checks. NumPy and SciPy compute 144 1-D and 44 2-D cases (every method and extrapolation, at, between and outside breakpoints, exact ties) and the four sizing rows; the page recomputes every one at build time. The generated C was compiled and run on all of them, and the generated Python snippets were run on 26.
Free counselling

From reading a table to building the model around it.

Lookup tables are where test data meets a control model: engine maps, cell tables, motor efficiency maps. A Skill-Lync counsellor can map the MATLAB, Simulink or EV course that fits your branch, year and the roles you want.

Talk to a MATLAB and Simulink course counsellor

Free. We call you back, usually the same day.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.