Black FridayUpgrade your career this Black Friday. Get up to ₹60,000 Scholarship on IIT programsUp to ₹60K Black Friday Scholarship52 seats leftOffer ends Fri, 27 Nov, 11:59 pm IST.

Black Friday Scholarship – IIT Jammu & IIT Roorkee

The best Black Friday deal isn't a gadget. It's your next career move.

Get up to ₹60,000 Black Friday Scholarship on our PG programs with IIT Jammu and iHUB DivyaSampark, IIT Roorkee. IIT certification, 12 live sessions with IIT faculty and 100% placement assistance.

Only 52 seats left. Offer ends Fri, 27 Nov, 11:59 pm IST

3,905 engineers placed since 2019 · 1,276 hiring companies

By submitting you agree to our Terms and Privacy Policy.

Your free demo class is requested

Browse courses

What Is a Lookup Table? Explained with Worked Examples (Simulink, C, FPGA)

A lookup table swaps a calculation for a stored answer. See how breakpoints, interpolation and extrapolation work, with verified 1-D and 2-D worked examples, a breakpoint-sizing rule, the Simulink blocks to use in R2026b, and a C implementation.

What Is a Lookup Table? Explained with Worked Examples (Simulink, C, FPGA)

A lookup table is a stored array of output values that replaces a calculation with a fetch. You record a function at chosen input points, called breakpoints. At run time the system finds the two breakpoints either side of the input and interpolates between their stored outputs. That is how engine maps, battery models and motor controllers in Simulink (and in the C code generated from them) produce answers in microseconds.

In short

  • A table for with breakpoints −2, −1, 0, 1, 2 returns 5.9 at x = 1.7 with linear interpolation. The true value is 4.913, so five points are far too few for that curve.
  • Linear-interpolation error shrinks with the square of the spacing: . Fifty evenly spaced points bring the table's worst error down to 0.0098. A quarter-wave sine table needs 57 points for 0.0001.
  • Simulink's 1-D Lookup Table block (R2026b) offers six interpolation methods and four extrapolation methods. It defaults to Linear point-slope interpolation, Linear extrapolation and binary search.
  • Since R2026b, MathWorks labels the Lookup Table Dynamic block "not recommended". Use 1-D Lookup Table with table data fed in as an input port instead.

The worked numbers in this guide come from a short Python script that Skill-Lync keeps alongside the post. The battery example uses the default table that ships with MathWorks' Battery (Table-Based) block, so you can open the same numbers in MATLAB and check them yourself.

1-D lookup table for y = x cubed with breakpoints -2 to 2. At x = 1.7 linear interpolation gives 5.9, nearest gives 8, flat gives 1, true value 4.913. At x = 2.5 linear extrapolation gives 11.5, clip gives 8, true 15.625.
The same five-point table answers x = 1.7 in three different ways, depending on the interpolation method. Past the last breakpoint, the extrapolation setting decides the output.

What is a lookup table, in plain terms?

A lookup table stores a function's outputs at known inputs, so the system looks the answer up instead of computing it. It has two parts. The breakpoints are the input values, and the table data holds the matching outputs. Inputs that fall between breakpoints are interpolated. Inputs outside the range are extrapolated or clipped.

Think of the steam tables or the gear-ratio chart in a design data book. You don't solve the equation of state every time. You find the two nearest rows and read between them. A lookup table block does the same job, at every time step of a simulation or every cycle of a controller.

MathWorks gives three reasons to use one, and all three show up in real engineering work:

  • The function is expensive. A table can be faster than evaluating the maths directly, which matters on a microcontroller running a 10 kHz motor-control loop.
  • There is no formula. The relationship is only known from tests. An engine's torque at each speed and throttle position, or a cell's open-circuit voltage at each state of charge, comes from a dynamometer or a battery cycler, not from an equation.
  • The hardware is integer-only. With evenly spaced breakpoints the index can be found without a division, which saves both time and memory in fixed-point code.

How does a lookup table compute an output? A worked 1-D example

The block runs three steps. It finds the interval that contains the input, computes how far along that interval the input sits (the fraction, from 0 to 1), then applies the interpolation rule. For linear interpolation between breakpoints and :

Take the old example from this post: approximate on [−2, 2] with breakpoints −2, −1, 0, 1, 2. The table data is −8, −1, 0, 1, 8. Now ask for x = 1.7:

  1. Index search. 1.7 lies between breakpoints 1 and 2.
  2. Fraction. .
  3. Interpolate. .

The true value is , so the table is off by about 1.0. That isn't a bug. The straight line between (1, 1) and (2, 8) simply doesn't 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 where the curve bends, and the next section shows how many.

Flat, nearest, linear and splines: what changes?

Method (Simulink name)Rulex = 1.7 on the x³ table
FlatHold the value at the interval's lower breakpoint1
NearestTake the value at the closest breakpoint8
Linear point-slope (default)Straight line between the two neighbours5.9
Linear LagrangeThe same straight line, written in Lagrange form5.9
Cubic spline, Akima splineSmooth curve through several neighboursCloser: a natural cubic spline gives 5.49 (cubic spline needs scalar signals)

Flat and Nearest suit tables whose output really is stepped, such as a gear number or a fault code, or a sensor that reports discrete levels. Linear is the workhorse. Splines follow smooth physical curves with fewer points but cost more arithmetic per call. Simulink only lets you pick Cubic spline extrapolation if interpolation is also Cubic spline, and the same pairing rule applies to Akima.

The old version of this post also used a sinh table with breakpoints −5 to 5. At x = 1.4, Nearest returns sinh(1) = 1.1752 and Linear returns 2.1559, while the true value is 1.9043. Neither answer is good, because sinh curves steeply and the spacing is a whole unit. That is the real lesson of the example.

What happens when the input is outside the table?

Outside the breakpoint range, Simulink either extends the end segment (Linear, the default) or holds the last value (Clip). Spline extrapolation is also available. On the x³ table at x = 2.5, Linear extrapolation gives 11.5, Clip gives 8, and the true value is 15.625. Choose based on what the physics does past the edge of your data.

The arithmetic: Linear extrapolation keeps the slope of the last interval, , so . Clip simply returns the end value, 8. In practice Clip is the safer default for measured maps. A battery's voltage below 0% state of charge, or an engine's torque above its rated speed, is not a straight-line continuation of the data, and extrapolating it can drive a controller into nonsense. MathWorks' Battery (Table-Based) block, for example, defaults its extrapolation to Nearest, which holds the end value.

If an out-of-range input means something has gone wrong, say so. The block's Diagnostic for out-of-range input can be set to None, Warning or Error. Since R2025a, the old "remove protection" option has been replaced by Assume input is within range. Tick it only when you can prove the input never leaves the table, because the generated code then skips the range checks.

How many breakpoints does a lookup table need?

For linear interpolation with spacing h, the worst-case error is at most , where f″ is the curve's second derivative. Choose h from the accuracy you need, then count the points. Halving the spacing cuts the error by four. Put extra breakpoints only where the curve bends most.

Worked example 1: the x³ table. On [−2, 2], , so . With h = 1 the bound is . The actual worst error on the [1, 2] interval is 1.128, at x = 1.528, which sits inside the bound. To hold the error to 0.01 you need . That means 4/0.0816, rounded up to 49 intervals, or 50 breakpoints. The script checked the 50-point table at 200,001 inputs and found a worst error of 0.0098.

Worked example 2: a sine table for a motor controller. Field-oriented control of a PMSM motor computes sin θ and cos θ every PWM cycle. On [0, π/2], . For an error of 0.0001, rad, so 56 intervals or 57 points. Symmetry does the rest: the other three quarters of the wave are mirror images, so a full-wave table would need 225 points for the same accuracy. Simulink's Sine block uses exactly this quarter-wave trick in its fixed-point lookup implementation.

Log-log plot of maximum linear interpolation error against number of evenly spaced breakpoints. The x cubed table on -2 to 2 reaches 0.0098 at 50 points; the sine table on 0 to pi/2 reaches 0.000098 at 57 points. Both follow the h squared bound.
Measured worst-case error (solid) tracks the bound (dashed). Each tenfold increase in points cuts the error a hundredfold.

Memory is usually the other constraint. A 20 × 20 table of single-precision floats takes 20 × 20 × 4 = 1,600 bytes, plus 160 bytes for the two breakpoint vectors: 1,760 bytes in all. That's nothing on a PC and noticeable on a small automotive controller holding dozens of maps. MathWorks' Lookup Table Optimizer (part of Fixed-Point Designer) automates the trade-off. It searches for the smallest table and data types that meet an error tolerance you set.

How does a 2-D lookup table work? A battery voltage example

A 2-D table maps two inputs to one output over a grid. To read it, interpolate along one input at the two bracketing rows, then interpolate between those results along the other input. This is bilinear interpolation. In effect, each of the four corner values gets a weight equal to the area of the rectangle diagonally opposite it.

MathWorks' Battery (Table-Based) block stores a cell's open-circuit voltage against state of charge (SOC) and temperature. Its default breakpoints are SOC = 0, 0.1, 0.25, 0.5, 0.75, 0.9, 1 and T = 278, 293, 313 K. What voltage does it give at SOC = 0.6 and 300 K (26.85 °C)?

  1. Bracket. SOC 0.6 lies between 0.5 and 0.75, and 300 K lies between 293 and 313 K. The four corner voltages are 3.71 and 3.72 V at SOC 0.5, and 3.93 and 3.94 V at SOC 0.75.
  2. Fractions. and .
  3. Interpolate across temperature. At SOC 0.5: V. At SOC 0.75: V.
  4. Interpolate across SOC. V.

Using the weights directly gives the same answer: V. Interpolation order doesn't matter, and the weights always add up to 1.

Bilinear interpolation cell: corners 3.71 V (SOC 0.5, 293 K), 3.72 V (SOC 0.5, 313 K), 3.93 V (SOC 0.75, 293 K), 3.94 V (SOC 0.75, 313 K). The query at SOC 0.6, 300 K gives weights 0.39, 0.21, 0.26, 0.14 and 3.8015 V.
Bilinear interpolation on MathWorks' default Battery (Table-Based) OCV table. Each corner's weight is the area of the rectangle diagonally opposite it.

The same block reads terminal resistance from a second SOC-by-temperature table with the same breakpoints. That repetition is where the Prelookup block earns its place.

Which Simulink lookup table block should you use?

Use 1-D, 2-D or n-D Lookup Table for most jobs. Use Prelookup with Interpolation Using Prelookup when several tables share the same inputs, so the search runs once. Use Direct Lookup Table (n-D) when the inputs are already integer indices and no interpolation is wanted. Avoid Lookup Table Dynamic in new models.

BlockUse it for
1-D / 2-D / n-D Lookup TableApproximating a function of one, two or many inputs
PrelookupComputing the index and fraction once
Interpolation Using PrelookupReusing that index and fraction across several tables
Direct Lookup Table (n-D)Fetching an element, vector or 2-D slice by index, with no interpolation
SineFixed-point sine or cosine from a quarter-wave table
Lookup Table DynamicListed by MathWorks as "not recommended"
Block diagram: a 1-D Lookup Table runs index search, fraction (0.6 - 0.5)/0.25 = 0.4, then interpolation. With Prelookup, index 3 and fraction 0.4 are computed once and shared by two Interpolation Using Prelookup blocks for the voltage and resistance tables.
Prelookup splits the search from the interpolation, so one SOC search feeds both the voltage table and the resistance table. Index 3 is zero-based: the fourth SOC breakpoint, 0.5.

Index search methods. Binary search (the default) finds the interval in about comparisons: 6 for 50 breakpoints, 10 for 1,000. Linear search is faster when the input moves only a little each time step, as it does for vehicle speed or cell temperature, especially with Begin index search using previous index result ticked. Evenly spaced points is the fastest option of all. It reads the offset and spacing from the first two breakpoints and computes the index directly, with no search.

For a step-by-step walk through the block dialog with a y = 2x example, see our companion post on how to use a lookup table in Simulink.

Where are lookup tables used in engineering?

Lookup tables sit wherever a measured relationship has to run fast. In vehicles that means engine torque and fuel maps, battery voltage and resistance tables, and motor efficiency maps. They also linearise sensors, such as thermistors, and supply the sine values in motor and inverter control. FPGAs build all their logic from tiny lookup tables.

  • EV and battery modelling. State-of-charge estimation in a battery management system leans on OCV-SOC tables. Our explainer on how a BMS works shows where they fit.
  • Calibration. In model-based design, the control algorithm is fixed early while calibration engineers tune the table data on test rigs. Keeping tables in a Simulink data dictionary keeps that data separate from the model.
  • FPGAs. In AMD 7-series FPGAs, each slice has four 6-input LUTs. A 6-input LUT is a 64-bit memory (2⁶ = 64 entries), so it can implement any Boolean function of six inputs by storing that function's truth table.
  • Software and spreadsheets. Precomputed tables (CRC tables, gamma curves, trigonometry in games) trade memory for speed. Excel's XLOOKUP is the same idea for data. It returns an exact match by default rather than interpolating.

How do you write a lookup table in C?

The generated code behind a 1-D Lookup Table boils down to a search and one interpolation. Here is the same idea by hand, with Clip extrapolation. It returns 5.9 for x = 1.7 on the x³ table:

/* breakpoints bp[0..n-1] strictly increasing, table tb[0..n-1] */
float lut1d(const float *bp, const float *tb, int n, float x)
{
    if (x <= bp[0])     return tb[0];       /* clip below */
    if (x >= bp[n - 1]) return tb[n - 1];   /* clip above */
    int lo = 0, hi = n - 1;                 /* binary search */
    while (hi - lo > 1) {
        int mid = (lo + hi) / 2;
        if (x < bp[mid]) hi = mid; else lo = mid;
    }
    float f = (x - bp[lo]) / (bp[hi] - bp[lo]);   /* fraction 0..1 */
    return tb[lo] + f * (tb[hi] - tb[lo]);
}

On a fixed-point controller you would store integers, choose power-of-two spacing so the division becomes a shift, and pick data types so the multiply can't overflow. Fixed-Point Designer and Embedded Coder handle exactly those steps for a Simulink model.

Lookup tables are one of the first things you meet in MATLAB and Simulink work. They run through EV powertrain and battery models end to end. Skill-Lync's MATLAB and Simulink basics course covers the blocks from the ground up. The battery technology for EVs course uses table-based cell models in real projects. Not sure which suits your branch and year? Talk to a Skill-Lync counsellor.

Frequently asked questions

What is the difference between a lookup table and a function?

A function computes its output from a formula every time it runs. A lookup table stores outputs at chosen input points and interpolates between them. The table trades memory for speed and can represent test data that has no formula. Its accuracy depends on breakpoint spacing: for linear interpolation the error falls with the square of that spacing.

What are breakpoints in a lookup table?

Breakpoints are the input values at which the table stores outputs, such as SOC = 0, 0.1, 0.25 and so on. They must be strictly increasing. They can be evenly spaced, which allows the fastest index calculation, or uneven, which lets you put more points where the curve bends. Each input dimension of a table has its own breakpoint vector.

Is linear interpolation accurate enough?

Usually, if the breakpoints are dense enough. The worst-case error is at most . The x³ table on [−2, 2] needs 50 evenly spaced points to stay within 0.01. If memory is tight and the curve is smooth, a cubic or Akima spline reaches the same accuracy with fewer points, at the cost of more arithmetic per call.

Should I use Clip or Linear extrapolation?

Use Clip for measured maps, such as battery voltage or engine torque, where the physics past the last test point is unknown. Clip holds the end value instead of extending a slope that may not exist. Use Linear only when the relationship stays straight beyond the data. If inputs should never leave the table, set the diagnostic to Error.

Is the Lookup Table Dynamic block still used?

Since R2026b, MathWorks lists Lookup Table Dynamic as "not recommended". For table data that changes during simulation, use the 1-D Lookup Table block with the Source of its table data (and breakpoints, if needed) set to Input port. Older models and tutorials, including the 2023 version of this post, still use the old block.

What is a LUT in an FPGA?

In an FPGA, a LUT is a tiny memory that implements logic. A 6-input LUT stores 64 bits, one output for each combination of its six inputs, so it can realise any Boolean function of six variables. AMD's 7-series devices group four such LUTs with eight flip-flops into a slice, and two slices into a configurable logic block.

Sources and further reading

Want this on your résumé?

Talk to a 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.

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.