MATLAB Answers

Is there any way of optimization of generated code for disabled subsystem in MATLAB R2016b?

1 view (last 30 days)
There are 2 enabled subsystems triggered by boolean constants. I have configured "function packaging" setting available in code generation section of block parameter for both subsystems. While doing code generation, I changed value of one of the boolean constants to zero to disable the subsystem. But the generated code contains declaration of global variable (BooleanSignalTwo) which is not used by any function. This is resulting in increase in overall memory footprint.
Is there any way to optimize generated code for disabled subsystem so as to avoid auto code generation for global variable used to disable that subsystem ?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 2 Aug 2020
  1. Considering that only one subsystem being activated at one point of time in code, it is not the best modelling technique to use enabled subsystem for this. A better way to achieve this is to use* Variant Subsystems* (<https://www.mathworks.com/help/releases/R2016b/ecoder/ug/represent-variants-in-generated-code.html>) where you can have both subsystems as variants (<https://www.mathworks.com/help/releases/R2016b/simulink/variant-systems.html>) and set the conditions based on the parameters.
  2. If your architecture has a lot of legacy model and its difficult for you to modify all enabled subsystem logic, you can replace merge blocks with Variant Sources (<https://www.mathworks.com/help/simulink/slref/variantsource.html>) with appropriate conditions. So the generated code does not generate unused global variables.

  0 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!