SPRADI0 July 2024
The configurations showcased in the table can be manually configured by configuring each parameter in the Hardware Settings in Simulink. To avoid manual effort, MATLAB also allows to configure settings in Simulink through MATLAB script.
The optimized code generation configuration can also be simply parsed through a script by either including the script in the existing model or just by running the script once to configure all settings before running the application code. The parameter 'mdl' in the script needs to reflect the name of the model in use to correctly configure the settings. It can be validated, if the settings are configured, by manually checking the configurations in the Hardware Settings in Simulink window.
%% 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