# 2-D Lookup Table (`lookup2d`)

> Looks up an output from a table over two inputs, with bilinear interpolation between the grid points.

![lookup2d](https://voltecx-web.nguyenvanqui291.workers.dev/docs/reference/img/lookup2d.svg)

[Component reference](https://voltecx-web.nguyenvanqui291.workers.dev/docs/reference/) · [繁體中文](https://voltecx-web.nguyenvanqui291.workers.dev/zh/docs/reference/control/lookup2d/)

**Group:** Control · **Kind:** `{"block":"lookup2d","kind":"control"}`

## When to use it

Use it for a value that depends on two signals: a switching-loss map against current and temperature, a flux map Ld or Lq against id and iq, or an MTPA table. Use Lookup Table for one input.

## Pins

| Pin | Domain | Meaning |
|---|---|---|
| `x` | signal | First input, looked up in xs |
| `y` | signal | Second input, looked up in ys |
| `out` | signal | Interpolated value from zs |

## Common parameters

- `xs`: Grid points of input x, smallest first, with commas (Default: required)
- `ys`: Grid points of input y, smallest first, with commas (Default: required)
- `zs`: Table values: one row per xs value separated by semicolons, one value per ys value in each row (Default: required)

## Parameters

| Key | Unit | Default | Typical range | Description |
|---|---|---|---|---|
| `xs` | — | required |  | Grid points of input x, smallest first, with commas |
| `ys` | — | required |  | Grid points of input y, smallest first, with commas |
| `zs` | — | required |  | Table values: one row per xs value separated by semicolons, one value per ys value in each row |

_Parameter descriptions are in English in both languages._

## Model

zs holds one row per xs value, rows separated by semicolons, and each row one value per ys value, so the value in row i and column j belongs to the point (xs i, ys j). Inside a grid cell the output is the bilinear interpolation of the four corners: first along y in the two rows around x, then along x between those two results. It is exact at the grid points and for any function a + b·x + c·y + d·x·y. Outside the grid each input is held at the nearest edge (no extrapolation). The block has direct feedthrough and no state.

## Common mistakes

- xs and ys must rise strictly, zs must have exactly one row per xs value and one value per ys value in every row, or the build stops and names the row. The table is at most 65536 values.
- Outside the grid the output stays flat. An operating point that leaves the table looks like saturation without a warning, so cover the full range of both inputs.

Problems rules: `compile.error`

## Datasheet and sources

The table comes from your own data or from a data sheet's family of curves, such as the turn-on energy against current at two or three temperatures; each curve read at the same currents is one column. Code generation writes the interpolation as a chain of comparisons for a grid of up to 64 points per axis and 256 values; a larger table is left out with the reason.

## Example

Open the example with the command `file.openExample` and the name `demo:lookup2d`.

---
Generated by `cargo xtask reference` from the usage texts and parameter specs. Do not edit by hand.
