ZHCAE84 July 2024
表中展示的配置可以通过在 Simulink 的 Hardware Settings 中配置每个参数来手动配置。为了避免手动操作,MATLAB 还允许通过 MATLAB 脚本在 Simulink 中配置设置。
优化的代码生成配置也可以通过脚本轻松解析,方法是在现有模型中包含脚本,或者直接在运行应用代码之前运行一次脚本来配置所有设置。脚本中的参数“mdl”需要反映所用模型的名称,才能正确配置设置。如果配置了这些设置,则可以通过在 Simulink 窗口中手动检查 Hardware Settings 中的配置来验证这些设置。
%% Load the model
mdl = 'TIDM_02012_F280039_MBD';%Model Name
load_system(mdl);
%% Set Build Configurations and Prioritized Objectives in Code Generation tab
set_param(mdl,'BuildConfiguration','Faster Runs') ; %Build Configurations
set_param(mdl,'ObjectivePriorities','Execution efficiency'); %Prioritized Objectives
%% Set Level, Priority in Optimization levels and enable some advanced Parameters in Optimization tab
set_param(mdl,'OptimizationPriority','speed');%Optimization Priority
set_param(mdl,"OptimizationCustomize","off");%Customize Optimizations Checkbox
%% TODO: Check -- updated Code Config > Optimization > default parameter behaviour to inlined instead of tunable to make the below config work
set_param(mdl,"InlineInvariantSignals","on");%Inline Invariant Signals
set_param(mdl,"EfficientMapNaN2IntZero","on");% Removes code from float to int with saturation mapping NaN to zero.
%% Remove support for non-finite, complex and absolute time Interface tab
set_param(mdl,"SupportAbsoluteTime","off");%Remove Absolute time support
set_param(mdl,"SupportComplex","off");%Remove Complex Number support
set_param(mdl,"SupportNonFinite","off");%Remove Non-Finite Number support
%% Application Lifetime setting
set_param(mdl,"LifeSpan","1");%Remove Absolute time support