This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

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 two Simulink.LookupTable objects in the base workspace.

LUTForInst1 = Simulink.LookupTable;
LUTForInst2 = Simulink.LookupTable;

Specify table and breakpoint data for each object.

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

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

LUTForInst1.StructTypeInfo.Name = 'LUTArg_Type';
LUTForInst2.StructTypeInfo.Name = 'LUTArg_Type';

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 LUTForInst2.

set_param('ex_arg_LUT/Model','ParameterArgumentValues',...
    struct('LUTArg','LUTForInst1'))
set_param('ex_arg_LUT/Model1','ParameterArgumentValues',...
    struct('LUTArg','LUTForInst2'))

Each instance of ex_arg_LUT_ref uses the table and breakpoint data stored in one of the Simulink.LookupTable objects in the base workspace.