www.gusucode.com > simulink 案例源码程序 matlab代码 > simulink/ConfigureInstanceSpecificDataForLookupTablesExample.m
%% Configure Instance-Specific Data for Lookup Tables % 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. % % # In the referenced model workspace, create |Simulink.LookupTable| objects. % In lookup table blocks that are in the model, use the objects to set the % table and breakpoint data. % # Configure the objects as model arguments by using the *Model arguments* % parameter in the Model Explorer. % # Create |Simulink.LookupTable| objects to % store the instance-specific data. For example, if you configure a single % |Simulink.LookupTable| object in the referenced model workspace as a % model argument, to store instance-specific data for two instances of the % referenced model (Model blocks in the parent model), create two % |Simulink.LookupTable| objects in the base workspace. % # Configure all of the |Simulink.LookupTable| objects to use the same % structure type name. In the property dialog box, under *Struct Type % definition*, set *Name* to the same value. % # Use the instance-specific objects to set argument values in Model % blocks. For example, in each Model block, use one of the % instance-specific |Simulink.LookupTable| objects from the base workspace. % % You cannot use |Simulink.Breakpoint| objects or |Simulink.LookupTable| % objects that refer to |Simulink.Breakpoint| objects as model arguments. %% Create Example Models % Create the example model |ex_arg_LUT_ref|, which represents a reusable % algorithm. open_system('ex_arg_LUT_ref') %% % Create the example model |ex_arg_LUT|, which uses the reusable algorithm % twice. open_system('ex_arg_LUT') %% Configure Model Arguments in Referenced Model % Use the Model Explorer to create a |Simulink.LookupTable| object in the % referenced model workspace (|ex_arg_LUT_ref|). Name the object |LUT_arg|. % % In the Dialog pane (the right pane) of the Model Explorer, set *Number of % table dimensions* to |2|. Under *Table* and *Breakpoints*, 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. % % Under *Struct Type definition*, set *Name* to |LUT_arg_Type|. % % Click *Apply*. % % In the *Model Hierarchy* pane, select the node that corresponds to the % referenced model workspace. % % In the Dialog pane, set *Model arguments* to |LUT_arg|. Click *Apply*. % % In the referenced model, in the n-D Lookup Table block, set *Data % specification* to |Lookup table object|. Set *Name* to |LUT_arg|. % % Save the referenced model. % % At the command prompt, you can use these commands to create and configure % the object. temp = Simulink.LookupTable; temp.Table.Value = [3 4; 1 2]; temp.Breakpoints(1).Value = [1 2]; temp.Breakpoints(2).Value = [3 4]; temp.StructTypeInfo.Name = 'LUT_arg_Type'; mdlwks = get_param('ex_arg_LUT_ref','ModelWorkspace'); assignin(mdlwks,'LUT_arg',copy(temp)) set_param('ex_arg_LUT_ref','ParameterArgumentNames','LUT_arg') set_param('ex_arg_LUT_ref/n-D Lookup Table',... 'DataSpecification','Lookup table object','LookupTableObject','LUT_arg') save_system('ex_arg_LUT_ref') %% Create Instance-Specific Argument Values % At the command prompt, create two |Simulink.LookupTable| objects in the % base workspace. LUTForInst1 = Simulink.LookupTable; LUTForInst2 = Simulink.LookupTable; %% % Specify breakpoint and table 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 a structure type name. % Match this name with the name specified by the object in the referenced % model workspace. LUTForInst1.StructTypeInfo.Name = 'LUT_arg_Type'; LUTForInst2.StructTypeInfo.Name = 'LUT_arg_Type'; %% % In the |ex_arg_LUT| model, in the top Model block, set *Model argument % values* to |LUTForInst1|. % % In the bottom Model block, set *Model argument values* to |LUTForInst2|. % % At the command prompt, you can use these commands to configure the Model % blocks. set_param('ex_arg_LUT/Model','ParameterArgumentValues','LUTForInst1') set_param('ex_arg_LUT/Model1','ParameterArgumentValues','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.