www.gusucode.com > simulinkcoder 案例源码程序 matlab代码 > simulinkcoder/ImproveReadabilityParamValuesAsMacrosExample.m
%% Improve Code Readability by Generating Block Parameter Values as Macros % When you generate efficient code by inlining the numeric values of block % parameters (with the configuration parameter *Default parameter % behavior*), you can configure scalar parameters to appear as macros % instead of literal numbers. Each macro has a unique name that is based on % the name of the corresponding block parameter. % % Open the example model |sldemo_fuelsys_dd_controller|. sldemo_fuelsys_dd_controller %% % The model uses these configuration parameter settings: % % * *Default parameter behavior* set to |Inlined|. % * *System target file* set to |ert.tlc|. % % Set the configuration parameter *Generate scalar inlined parameters as* % to |Macros|. set_param('sldemo_fuelsys_dd_controller','InlinedPrmAccess','Macros') %% % Generate code from the model. rtwbuild('sldemo_fuelsys_dd_controller') %% % The header file |sldemo_fuelsys_dd_controller_private.h| defines several % macros that represent inlined (nontunable) block parameters. For example, % the macros |rtCP_DiscreteFilter_NumCoe_EL_0| and % |rtCP_DiscreteFilter_NumCoe_EL_1| represent floating-point constants. file = fullfile('sldemo_fuelsys_dd_controller_ert_rtw',... 'sldemo_fuelsys_dd_controller_private.h'); rtwdemodbtype(file,'#define rtCP_DiscreteFilter_NumCoe_EL_0',... 'rtCP_DiscreteFilter_NumCoe_EL_1',1,1) %% % The comments above the macro definitions indicate that the code generated for a Discrete Filter % block uses the macros. rtwdemodbtype(file,'Computed Parameter: DiscreteFilter_NumCoef',... 'Referenced by: ''<S12>/Discrete Filter''',1,1) %% % Click the hyperlink to navigate to the block in the model.