Main Content

Configure Instance-Specific Data for Lookup Tables Programmatically

When you use Simulink.LookupTable objects to store and configure lookup table data for ASAP2 or AUTOSAR code generation (for example, STD_AXIS or CURVE), you can configure the objects as model arguments. You can then specify unique table data and breakpoint data for each instance of a component.

This example shows how to configure multiple instances of a referenced model to use different values for the same block parameter by using lookup tables and the command prompt.

Configure Model Arguments in Referenced Model

Open model ex_arg_LUT_ref, which represents a reusable algorithm.

open_system('ex_arg_LUT_ref')

Create a Simulink.LookupTable object in the base workspace. For this example, name the object LUTArg.

temp = Simulink.LookupTable;

Specify values for the table and breakpoint data. When you simulate or generate code directly from ex_arg_LUT_ref, the model uses these values.

temp.Table.Value = [3 4; 1 2];
temp.Breakpoints(1).Value = [1 2];
temp.Breakpoints(2).Value = [3 4];

Set the structure name to LUTArg_Type.

temp.StructTypeInfo.Name = 'LUTArg_Type';

Copy the structure to the model workspace.

mdlwks = get_param('ex_arg_LUT_ref','ModelWorkspace');
assignin(mdlwks,'LUTArg',copy(temp))

Specify LUTArg as a model argument.

set_param('ex_arg_LUT_ref','ParameterArgumentNames','LUTArg')

For the n-D Lookup Table block, set 'Data specification' to 'Lookup table object' and set the name to LUTArg.

set_param('ex_arg_LUT_ref/n-D Lookup Table',...
    'DataSpecification','Lookup table object','LookupTableObject','LUTArg')

Create Instance-Specific Argument Values

Open model ex_arg_LUT, which uses the reusable algorithm twice.

open_system('ex_arg_LUT')

Create a Simulink.LookupTable object in the base workspace.

LUTForInst1 = Simulink.LookupTable;

Specify table and breakpoint data for the object.

LUTForInst1.Table.Value = [8 7; 6 5];
LUTForInst1.Breakpoints(1).Value = [5 6];
LUTForInst1.Breakpoints(2).Value = [3 4];

Specify the structure name to match the name specified by the object in the referenced model workspace.

LUTForInst1.StructTypeInfo.Name = 'LUTArg_Type';

Use a structure to create the instance-specific argument value for the second Model block. Specify the breakpoint and table data for the structure.

StructForInst2.Table = [9 8; 7 7];
StructForInst2.BP1 = [3 4];
StructForInst2.BP2 = [5 6];

In the ex_arg_LUT model, for model instance Model, set the value of LUTArg to LUTForInst1. For model instance Model1, set the value of LUTArg to StructForInst2.

instSpecParams = get_param('ex_arg_LUT/Model','InstanceParameters');
instSpecParams(1).Value = 'LUTForInst1';
instSpecParams1 = get_param('ex_arg_LUT/Model1','InstanceParameters');
instSpecParams1(1).Value = 'StructForInst2';
set_param('ex_arg_LUT/Model','InstanceParameters',instSpecParams);
set_param('ex_arg_LUT/Model1','InstanceParameters',instSpecParams1);

One instance of ex_arg_LUT_ref uses the table and breakpoint data stored in the Simulink.LookupTable object in the base workspace and the other instance uses the table and breakpoint data stored in the structure.