Using the Prelookup and Interpolation Blocks
This example shows how to use the Prelookup and Interpolation Using Prelookup blocks.
Introduction
The Prelookup block computes index and interval fractions that the Interpolation Using Prelookup block uses for interpolation. When used together, these blocks perform the same operation as the n-D Lookup Table block. This example describes
Some cases where using the individual Prelookup and Interpolation blocks might provide better flexibility, and efficient simulation and code generation, than when using the n-D Lookup Table block alone.
How to select subtables in the Prelookup block.
How to perform breakpoint and table consistency between the Prelookup and Interpolation Using Prelookup blocks.
Model of Prelookup and Interpolation Using Prelookup Blocks Working Together
To see how Prelookup and Interpolation Using Prelookup blocks work together to perform a lookup algorithm without doing repetitive prelookups, open the model sldemoPrelookupInterpolation.slx
.
open_system("sldemoPrelookupInterpolation.slx")
The Prelookup blocks perform the index search portion of the computation.
The Interpolation Using Prelookup blocks perform the rest of the computation.
Efficient Simulation
In this model, two index search results are used in four blocks for a total of seven uses. An equivalent implementation using an n-D Lookup Table block requires seven index searches instead of two. By reusing the results of index searching and fraction calculation for different interpolations to achieve better runtime performance, this setup minimizes the number of index searches performed across a set of lookup tables.
Greater Flexibility
Using the Prelookup and Interpolation Using Prelookup blocks together also offers greater flexibility because they use an index search method that fits the breakpoints per dimension for further optimization. For example, the sldemoPrelookupInterpolation.slx
model contains two Prelookup blocks, each configured for a different index search method:
Prelookup 1 uses the Index search method > Evenly spaced points option to perform an index search for the first input
U1
, whose corresponding breakpoints are evenly spaced on this dimension.Prelookup 2 uses the Index search method > Binary search option to perform an index search for the second input
U2
, whose corresponding breakpoints are unevenly spaced.
In comparison, you can only configure an n-D Lookup Table block to use one index search method at a time for all inputs.
Model of Subtable Selection
To select subtables in the Interpolation Using Prelookup block, you can configure the block in such a way that the trailing dimensions of an n-D table can be marked as selection dimensions. This means that the input for that dimension is an integer used only to select a subtable, such as picking a 2-D plane from a 3-D table. The subtable is then interpolated normally.
Open the sldemoSubtableSelection.slx
model to see how to use the Interpolation using Prelookup block subtable selection feature to model interpolation on a subset of the table data.
open_system("sldemoSubtableSelection.slx")
To compose the table value in the Interpolation using Prelookup block, the block layers three 2-D tables, where each 2-D table is designed for a specific scenario. The input Subtable Selection selects the 2-D table for the scenario, after which the Interpolation block performs the 2-D interpolation.
To activate this interpolation mode, set the Interpolation block Number of sub-table selections dimensions parameter to a positive integer. The model interprets the specified value as the number of dimensions to select from the highest dimension of table data. For more information on choosing the selection dimension, see Interpolation Using Prelookup.
Checking Breakpoint and Table Data Consistency
To check breakpoint and table data consistency, ensure that the length of the Breakpoints data in the Prelookup blocks matches the corresponding dimension of the Table data in the connected Interpolation Using Prelookup blocks. Simulink® always checks the consistency between the two blocks when updating the block diagram. If there is inconsistency between breakpoint and table data, the model returns errors.
See Also
n-D Lookup Table | Prelookup | Interpolation Using Prelookup