# Interpolation Using Prelookup

Use precalculated index and fraction values to accelerate approximation of N-dimensional function

• Library:

• ## Description

The Interpolation Using Prelookup block is most efficient when used with the Prelookup block. The Prelookup block calculates the index and interval fraction that specify how its input value `u` relates to the breakpoint data set. Feed the resulting index and fraction values into an Interpolation Using Prelookup block to interpolate an n-dimensional table. These two blocks have distributed algorithms. When combined together, they perform the same operation as the integrated algorithm in the n-D Lookup Table block. However, the Prelookup and Interpolation Using Prelookup blocks offer greater flexibility that can provide more efficient simulation and code generation. For more information, see Efficiency of Performance.

### Supported Block Operations

To use the Interpolation Using Prelookup block, you specify a set of table data values directly on the dialog box or feed values into the T input port. Typically, these table values correspond to the breakpoint data sets specified in Prelookup blocks. The Interpolation Using Prelookup block generates output by looking up or estimating table values based on index and interval fraction values fed from Prelookup blocks. Labels for the index and interval fraction appear as `k` and `f` on the Interpolation Using Prelookup block icon.

When inputs for index and interval fraction...The Interpolation Using Prelookup block...
Map to values in breakpoint data setsOutputs the table value at the intersection of the row, column, and higher dimension breakpoints
Do not map to values in breakpoint data sets, but are within rangeInterpolates appropriate table values using the Interpolation method you select
Do not map to values in breakpoint data sets, and are out of rangeExtrapolates the output value using the Extrapolation method you select

### How The Block Interpolates a Subset of Table Data

You can use the Number of sub-table selection dimensions parameter to specify that interpolation occur only on a subset of the table data. To activate this interpolation mode, set this parameter to a positive integer. This value defines the number of dimensions to select, starting from the highest dimension of table data for the default column-major algorithm. Therefore, the value must be less than or equal to the Number of table dimensions.

For row-major algorithms, the interpolation starts from the first or lowest dimension of the table data.

For nonzero values, the subtable selection behavior is optimized for row-major layout when you select the Math and Data Types > Use algorithms optimized for row-major array layout configuration parameter.

Suppose that you have 3-D table data in your Interpolation Using Prelookup block. This behavior applies for the column-major algorithm.

Number of Selection DimensionsAction by the BlockBlock Appearance
0Interpolates the entire table and does not activate subtable selectionDoes not change
1Interpolates the first two dimensions and selects the third dimension Displays an input port with the label `s3` that you use to select and interpolate 2-D tables
2Interpolates the first dimension and selects the second and third dimensions Displays two input ports with the labels `s2` and `s3` that you use to select and interpolate 1-D tables

Subtable selection uses zero-based indexing. For an example of interpolating a subset of table data, type `sldemo_bpcheck` at the MATLAB® command prompt.

For 2-D or n-D interpolation without subtable selection, the column-major and row-major algorithms may differ in the order of output calculations, causing slight different numerical results.

## Ports

### Input

expand all

Zero-based index, `k`, specifying the interval containing the input `u` for the first dimension of the table.

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64` | `fixed point`

Fraction, `f`, representing the normalized position of the input within the interval, `k`, for the first dimension of the table.

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64` | `fixed point`

Zero-based index, `k`, specifying the interval containing the input `u` for the `n`-th dimension of the table.

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64` | `fixed point`

Fraction, `f`, representing the normalized position of the input within the interval, `k`, for the `n`-th dimension of the table.

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64` | `fixed point`

Inputs to the kf1 port contain index `k` and fraction `f` specified as a bus object.

#### Dependencies

To enable this port, select the Require index and fraction as a bus check box.

The number of available `kf` input ports depends on the value of the Number of dimensions and Number of sub-table selection dimensions parameters.

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64` | `fixed point` | `bus`

Inputs to the kfn port contain index `k` and fraction `f` for the n-th dimension of the input, specified as a bus object.

#### Dependencies

To enable this port, select the Require index and fraction as a bus check box.

The number of available kf input ports depends on the value of the Number of dimensions and Number of sub-table selection dimensions parameters.

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64` | `fixed point` | `bus`

For column-major algorithm, the block uses inputs to the sm, sm+1, ... sn port to perform selection and interpolation within the subtables. `m` maps to the mth dimension of the table. n equals the Number of dimensions.

For row-major algorithm, the block uses inputs to the s1, s2,... ,sm port to perform selection and interpolation within the subtables. `m` maps to the mth dimension of the table. m equals the Number of sub-table selection dimensions.

#### Dependencies

To enable this port, the Number of sub-table selection dimensions must be a positive integer less than or equal to the Number of dimensions.

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64` | `Boolean` | `fixed point` | `enumerated` | `bus`

Table data values provided as input to port T. Typically, these table values correspond to the breakpoint data sets specified in Prelookup blocks. The Interpolation Using Prelookup block generates output by looking up or estimating table values based on index (`k`) and interval fraction (`f`) values fed from Prelookup blocks.

#### Dependencies

To enable this port, set Source to `Input port`.

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64` | `fixed point`

### Output

expand all

Approximation of N-dimensional function, computed by interpolating (or extrapolating) table data using values from the input index, `k`, and fraction, `f`.

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64` | `fixed point`

## Parameters

expand all

### Main

Table data

Specify the number of dimensions that the table data must have. The Number of dimensions defines the number of independent variables for the table.

To specify...Do this...

1, 2, 3, or 4

Select the value from the drop-down list.

A higher number of table dimensions

Enter a positive integer directly in the field.

The maximum number of table dimensions that this block supports is 30.

#### Programmatic Use

 Block Parameter: `NumberOfTableDimensions` Type: character vector Values: `'1' | '2' | '3' |'4' | ... | '30'` Default: `'2'`

Select this check box to combine index and fraction inputs in a bus.

To enable the Prelookup block to supply input to the Interpolation Using Prelookup block, set:

• Output selection to ```Index and fraction as bus```

• Output to ```Bus: <object name>```, where ```<object name>``` must be a valid bus object name accessible to the model

Regardless of this check box setting, the selection port always operates in nonbus mode.

#### Programmatic Use

 Block Parameter: `RequireIndexFractionAsBus` Type: character vector Values: `'off' | 'on'` Default: `'off'`

Specify whether to enter table data directly or use a lookup table object. If you set this parameter to:

• `Explicit values`, the Source and Value parameters are visible on the dialog box.

• `Lookup table object`, the Name parameter is visible on the dialog box.

#### Programmatic Use

 Block Parameter: `TableSpecification` Type: character vector Values: ```'Explicit values' | 'Lookup table object'``` Default: `'Explicit values'`

Specify whether to enter table data in the dialog box or to inherit the data from an input port. If you set Source to:

• `Dialog`, enter table data in the text box under Value

• `Input port`, verify that an upstream signal supplies table data to the table input port

#### Dependencies

To enable this parameter, set Specification to `Explicit values`.

#### Programmatic Use

 Block Parameter: `TableSource` Type: character vector Values: `'Dialog' | 'Input port'` Default: `'Dialog'`

Specify table data as an `N`-D array, where `N` is the value of the Number of dimensions parameter. You can edit the block diagram without specifying a correctly dimensioned matrix by entering an empty matrix (`[]`) or an undefined workspace variable in the Value edit field. For information about how to construct multidimensional arrays in MATLAB, see Multidimensional Arrays.

If you set Source to `Input port`, verify that an upstream signal supplies table data to the T input port. The size of table data must match the Number of table dimensions. For this option, the block inherits table attributes from the T input port.

To edit lookup tables using the Lookup Table Editor, click (see Edit Lookup Tables).

#### Dependencies

To enable this parameter and explicitly specify table values on the dialog box, you must set Specification to `Explicit values` and Source to `Dialog`.

#### Programmatic Use

 Block Parameter: `Table` Type: character vector Values: `scalar, vector, matrix, or N-D array`
 Default: `'sqrt([1:11]' * [1:11])'`

Specify the name of a `Simulink.LookupTable` object. A lookup table object references Simulink® breakpoint objects. If a `Simulink.LookupTable` object does not exist, click the action button and select . The corresponding parameters of the new lookup table object are automatically populated with the block information.

#### Dependencies

To enable this parameter, set Specification to `Lookup table object`.

#### Programmatic Use

 Block Parameter: `LookupTableObject` Type: character vector Value: `Simulink.LookupTable object` Default: `''`
Algorithm

Specify the method the block uses to interpolate table data. You can select `Linear point-slope`, `Flat`, `Nearest`, or `Linear Lagrange`. See Interpolation Methods for more information.

#### Programmatic Use

 Block Parameter: `InterpMethod` Type: character vector Values: ```'Flat' | 'Linear point-slope' | 'Nearest' | 'Linear Lagrange'``` Default: `'Linear point-slope'`

Specify the method the block uses to extrapolate values for all inputs that fall outside the range of the breakpoint data set. You can select `Clip` or `Linear`. See Extrapolation Methods for more information.

If the extrapolation method is `Linear`, the extrapolation value is calculated based on the selected linear interpolation method. For example, if the interpolation method is Linear Lagrange, the extrapolation method inherits the Linear Lagrange equation to compute the extrapolated value.

#### Dependencies

To enable the Extrapolation method parameter, set the Interpolation method to `Linear`.

The Interpolation Using Prelookup block does not support `Linear` extrapolation when the input or output signals specify integer or fixed-point data types.

#### Programmatic Use

 Block Parameter: `ExtrapMethod` Type: character vector Values: `'Clip' | 'Linear'` Default: `'Linear'`

Specify how block inputs for index (`k`) and interval fraction (`f`) access the last elements of n-dimensional table data. Index values are zero based.

This check box is relevant if the input index is equal to or larger than the table's last index for that dimension. Due to rounding, selecting and clearing this check box may result in differing results for the last index between simulation and code generation.

Check BoxBlock Behavior

`on`

Returns the value of the last element in a dimension of its table when:

• `k` indexes the last table element in the corresponding dimension

• `f` is `0`

`off`

Returns the value of the last element in a dimension of its table when:

• `k` indexes the next-to-last table element in the corresponding dimension

• `f` is `1`

#### Dependencies

This check box is visible only when:

• Interpolation method is `Linear point-slope` or `Linear Lagrange`

• Extrapolation method is `Clip`

Tip

When you select Valid index input may reach last index for an Interpolation Using Prelookup block, you must also select Use last breakpoint for input at or above upper limit for all Prelookup blocks that feed it. This action allows the blocks to use the same indexing convention when accessing the last elements of their breakpoint and table data sets.

#### Programmatic Use

 Block Parameter: `ValidIndexMayReachLast` Type: character vector Values: `'off' | 'on'` Default: `'off'`

Specify whether to produce a warning or error when the input is out of range. Options include:

• `None` — Produce no response.

• `Warning` — Display a warning and continue the simulation.

• `Error` — Terminate the simulation and display an error.

#### Programmatic Use

 Block Parameter: `DiagnosticForOutOfRangeInput` Type: character vector Values: `'None' | 'Warning' | 'Error'` Default: `'None'`

Specify the number of dimensions of the subtable that the block uses to compute the output. Follow these rules:

• To enable subtable selection, enter a positive integer.

This integer must be less than or equal to the Number of table dimensions.

• To disable subtable selection, enter `0` to interpolate the entire table.

For nonzero values, the subtable selection behavior is optimized for row-major layout when you select the Math and Data Types > Use algorithms optimized for row-major array layout configuration parameter.

For more information, see How The Block Interpolates a Subset of Table Data.

#### Programmatic Use

 Block Parameter: `NumSelectionDims` Type: character vector Values: ```'0' | '1' | '2' | '3' | '4' | ... | Number of table dimensions``` Default: `'0'`
Code generation
Check BoxResultWhen to Use

`on`

Generated code does not include conditional statements to check for out-of-range index inputs.

When the input `k` or `f` is out of range, it may cause undefined behavior for generated code.

For code efficiency

`off`

Generated code includes conditional statements to check for out-of-range index inputs.

For safety-critical applications

If your input is not out of range, you can select the Remove protection against out-of-range index in generated code check box for code efficiency. By default, this check box is cleared. For safety-critical applications, do not select this check box. If you want to select the Remove protection against out-of-range index in generated code check box, first check that your model inputs are in range. For example:

1. Clear the Remove protection against out-of-range index in generated code check box.

2. Set the Diagnostic for out-of-range input parameter to `Error`.

3. Simulate the model in normal mode.

4. If there are out-of-range errors, fix them to be in range and run the simulation again.

5. When the simulation no longer generates out-of-range input errors, select the Remove protection against out-of-range index in generated code check box.

Note

When you select the Remove protection against out-of-range index in generated code check box and the input `k` or `f` is out of range, the behavior is undefined for generated code.

Depending on your application, you can run the following Model Advisor checks to verify the usage of this check box:

• By Product > Embedded Coder > Identify lookup table blocks that generate expensive out-of-range checking code

• By Product > Simulink Check > Modeling Standards > DO-178C/DO-331 Checks > Check usage of lookup table blocks

Additionally, to determine if it is safe to select this check box, if you have a Simulink Design Verifier™ license, consider using the Detect Block Input Range Violations (Simulink Design Verifier) check.

This check box has no effect on the generated code when one of the following is true:

• The Prelookup block feeds index values to the Interpolation Using Prelookup block.

Because index values from the Prelookup block are always valid, no check code is necessary.

• The data type of the input `k` restricts the data to valid index values.

For example, unsigned integer data types guarantee nonnegative index values. Therefore, unsigned input values of `k` do not require check code for negative values.

#### Programmatic Use

 Block Parameter: `RemoveProtectionIndex` Type: character vector Values: `'off' | 'on'` Default: `'off'`

Specify the sample time as a value other than -1. For more information, see Specify Sample Time.

#### Dependencies

This parameter is not visible unless it is explicitly set to a value other than `-1`. To learn more, see Blocks for Which Sample Time Is Not Recommended.

#### Programmatic Use

 Block Parameter: `SampleTime` Type: character vector Values: scalar or vector Default: `'-1'`

### Data Types

Specify the table data type. You can set it to:

• A rule that inherits a data type, for example, `Inherit: Same as output`

• The name of a built-in data type, for example, `single`

• The name of a data type object, for example, a `Simulink.NumericType` object

• An expression that evaluates to a data type, for example, `fixdt(1,16,0)`

Click the button to display the Data Type Assistant, which helps you set the table data type.

Tip

Specify a table data type different from the output data type for these cases:

• Lower memory requirement for storing table data that uses a smaller type than the output signal

• Sharing of prescaled table data between two Interpolation Using Prelookup blocks with different output data types

• Sharing of custom storage table data in Simulink Coder™ generated code for blocks with different output data types

#### Programmatic Use

 Block Parameter: `TableDataTypeStr` Type: character vector Values: ```'Inherit: Inherit from table data' | 'Inherit: Same as output' | 'double' | 'single' | 'int8' | 'uint8' | 'int16' | 'uint16' | 'int32' | 'uint32' | 'int64' | 'uint64' | 'fixdt(1,16)' | 'fixdt(1,16,0)' | 'fixdt(1,16,2^0,0)' | ''``` Default: `'Inherit: Same as input'`

Specify the minimum value for table data as a finite, real, double, scalar. The default value is `[]` (unspecified).

#### Programmatic Use

 Block Parameter: `TableMin` Type: character vector Values: scalar Default: `'[]'`

Specify the maximum value for table data as a finite, real, double, scalar. The default value is `[]` (unspecified).

#### Programmatic Use

 Block Parameter: `TableMax` Type: character vector Values: scalar Default: `'[]'`

Specify the intermediate results data type. You can set it to:

• A rule that inherits a data type, for example, `Inherit: Same as output`

• The name of a built-in data type, for example, `single`

• The name of a data type object, for example, a `Simulink.NumericType` object

• An expression that evaluates to a data type, for example, `fixdt(1,16,0)`

Click the button to display the Data Type Assistant, which helps you set the data type attributes. For more information, see Specify Data Types Using Data Type Assistant.

Tip

Use this parameter to specify higher precision for internal computations than for table data or output data.

#### Programmatic Use

 Block Parameter: `IntermediateResultsDataTypeStr` Type: character vector Values: ```'Inherit: Inherit via internal rule' | 'Inherit: Same as output' | 'double' | 'single' | 'int8' | 'uint8' | 'int16' | 'uint16' | 'int32' | 'uint32' | 'int64' | 'uint64' | 'fixdt(1,16)' | 'fixdt(1,16,0)' | 'fixdt(1,16,2^0,0)' | ''``` Default: `'Inherit: Same as input'`

Specify the output data type. You can set it to:

• A rule that inherits a data type, for example, ```Inherit: Inherit via back propagation```

• The name of a built-in data type, for example, `single`

• The name of a data type object, for example, a `Simulink.NumericType` object

• An expression that evaluates to a data type, for example, `fixdt(1,16,0)`

Click the button to display the Data Type Assistant, which helps you set the output data type.

#### Programmatic Use

 Block Parameter: `OutDataTypeStr` Type: character vector Values: ```'Inherit: Inherit via back propagation' | 'Inherit: Inherit from table data' | 'double' | 'single' | 'int8' | 'uint8' | 'int16' | 'uint16' | 'int32' | 'uint32' | 'int64' | 'uint64' | 'fixdt(1,16,0)' | 'fixdt(1,16,2^0,0)' | 'fixdt(1,16,2^0,0)' | ''``` Default: `'Inherit: Inherit from table data'`

Specify the minimum value that the block should output as a finite, real-valued scalar. The default value is `[]` (unspecified). Simulink software uses this value to perform:

#### Programmatic Use

 Block Parameter: `OutMin` Type: character vector Values: scalar Default: `'[]'`

Specify the maximum value that the block should output as a finite, real-valued scalar. The default value is `[]` (unspecified). Simulink software uses this value to perform:

#### Programmatic Use

 Block Parameter: `OutMax` Type: character vector Values: scalar Default: `'[]'`

Specify the internal rule for intermediate calculations. Select `Speed` for faster calculations. If you do, a loss of accuracy might occur, usually up to 2 bits.

#### Programmatic Use

 Block Parameter: `InternalRulePriority` Type: character vector Values: `'Speed' | 'Precision'` Default: `'Speed'`

Select this parameter to prevent the fixed-point tools from overriding the data types you specify on this block. For more information, see Lock the Output Data Type Setting (Fixed-Point Designer).

#### Programmatic Use

 Block Parameter: `LockScale` Type: character vector Values: `'off' | 'on'` Default: `'off'`

Specify the rounding mode for fixed-point operations. For more information, see Rounding (Fixed-Point Designer).

Block parameters always round to the nearest representable value. To control the rounding of a block parameter, enter an expression using a MATLAB rounding function in the mask field.

#### Programmatic Use

 Block Parameter: `RndMeth` Type: character vector Values: ```'Ceiling' | 'Convergent' | 'Floor' | 'Nearest' | 'Round' | 'Simplest' | 'Zero'``` Default: `'Floor'`

Specify whether overflows saturate or wrap.

ActionRationaleImpact on OverflowsExample

Select this check box (`on`).

Your model has possible overflow, and you want explicit saturation protection in the generated code.

Overflows saturate to either the minimum or maximum value that the data type can represent.

The maximum value that the `int8` (signed, 8-bit integer) data type can represent is 127. Any block operation result greater than this maximum value causes overflow of the 8-bit integer. With the check box selected, the block output saturates at 127. Similarly, the block output saturates at a minimum output value of -128.

Do not select this check box (`off`).

You want to optimize efficiency of your generated code.

You want to avoid overspecifying how a block handles out-of-range signals. For more information, see Troubleshoot Signal Range Errors.

Overflows wrap to the appropriate value that is representable by the data type.

The maximum value that the `int8` (signed, 8-bit integer) data type can represent is 127. Any block operation result greater than this maximum value causes overflow of the 8-bit integer. With the check box cleared, the software interprets the overflow-causing value as `int8`, which can produce an unintended result. For example, a block result of 130 (binary 1000 0010) expressed as `int8`, is -126.

When you select this check box, saturation applies to every internal operation on the block, not just the output, or result. Usually, the code generation process can detect when overflow is not possible. In this case, the code generator does not produce saturation code.

#### Programmatic Use

 Block Parameter: `SaturateOnIntegerOverflow` Type: character vector Values: `'off' | 'on'` Default: `'off'`

## Block Characteristics

 Data Types `double` | `fixed point` | `integer` | `single` Direct Feedthrough `yes` Multidimensional Signals `yes` Variable-Size Signals `no` Zero-Crossing Detection `no`