www.gusucode.com > ecoder 案例源码程序 matlab代码 > ecoder/CtrlCodeGenForLookupTableAndBreakpointSetsExample.m

    %% Control Code Generation for Lookup Table and Breakpoint Sets
% Create a |Simulink.LookupTable| object named |LUTObj|. 
LUTObj = Simulink.LookupTable; 
%%
% Specify the table data.
LUTObj.Table.Value = [1.00 2.25 3.50 4.75 6.00; ...
                          7.25 8.50 9.75 11.00 12.25];
%%
% Specify the breakpoint set data. In the |Breakpoints| property, use
% the array index |2| to create an additional
% |Simulink.lookuptable.BreakpointInfo| object, which represents the second
% breakpoint set. 
LUTObj.Breakpoints(1).Value = [-1 1];

LUTObj.Breakpoints(2).Value = [-2 -1 0 1 2];
%%
% Specify data types for the lookup table and each breakpoint set.
LUTObj.Table.DataType = 'fixdt(1,16,2)';

LUTObj.Breakpoints(1).DataType = 'int16';

LUTObj.Breakpoints(2).DataType = 'int16';
%%
% Specify unique names for the structure fields that store the table data
% and breakpoint sets in the generated code.
LUTObj.Table.FieldName = 'myTable';

LUTObj.Breakpoints(1).FieldName = 'myBPSet1';

LUTObj.Breakpoints(2).FieldName = 'myBPSet2';
%%
% Export the structure variable definition from the generated code by using
% the storage class |ExportedGlobal|.
LUTObj.CoderInfo.StorageClass = 'ExportedGlobal';
%%
% Name the structure type in the generated code |LUTStructType|.
% Export the structure type definition to a generated header file named |myLUTHdr.h|.
LUTObj.StructTypeInfo.Name = 'LUTStructType';
LUTObj.StructTypeInfo.DataScope = 'Exported';
LUTObj.StructTypeInfo.HeaderFileName = 'myLUTHdr.h';
%%
% In an n-D Lookup Table block in a model, set *Data specification* to
% |Lookup table object| and *Name* to |LUTObj|.
load_system('myModel_LUTObj')
set_param('myModel_LUTObj/Lookup Table','DataSpecification','Lookup table object',...
    'LookupTableObject','LUTObj') 
%%
% Generate code from the model.
rtwbuild('myModel_LUTObj')
%%
% The generated code defines the structure type |LUTStructType| in the
% generated header file |myLUTHdr.h|.
file = fullfile('myModel_LUTObj_ert_rtw','myLUTHdr.h');
rtwdemodbtype(file,'typedef struct {','} LUTStructType;',1,1)
%%
% The code uses the global structure variable |LUTObj| to store the table
% and breakpoint set data. The table data is scaled based on the specified
% fixed-point data type.
file = fullfile('myModel_LUTObj_ert_rtw','myModel_LUTObj.c');
rtwdemodbtype(file,'LUTStructType LUTObj = {','/* Variable: LUTObj',1,1)