I have a parameter that is used only inside of a variant subsystem. How can I make sure that in the generated code this parameter is only defined if the variant is active?

1 view (last 30 days)
I have a model (call it "Parent") that contains a model reference ("Child"). Inside of "Child", there is a variant subsystem, and inside one of the variants (and not the others), a parameter called "myParam" (configured as a Simulink.Parameter object) is used. I want to generate code from "Parent", but I only want "myParam" to be defined if it is needed (i.e. its variant is the active one). Note that this actually occurs many times in my system, so this behavior is important for memory usage in the generated code.
Now, inside the generated code for "Child", the code for each variant is located is located inside "#if...#endif" statements that ensure that the code is only run if the variant is active, which is what I want. But, the definition of "myParam" is located in the code for "Parent" and it does not have these #if preprocessor guards.
How can I generate code so that "myParam" is only defined if it is used? Can I generate code so that the definition is inside of a preprocessor "#if...#endif" guard?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 21 Feb 2018
You can configure your model so that the generated code defining the parameter is placed inside #if...#endif statements. To do this, please try the following steps:
 
1) In the "Parent.slx" model's configuration parameters, turn on the 'Use owner from data object for data definition placement' setting in the Code Generation->Code Placement section
2) For the "myParam" parameter (and any others with a similar issue), go to its definition (e.g. in Model Explorer or in a Simulink Data Dictionary) and set the "Owner" property (under Code Generation Options->Custom Attributes) to "Child" (without the quotes)
Now when you generate code, the "myParam" parameter should be defined in "Child.c" and the definition should be inside of an #if...#endif statement.

More Answers (0)

Categories

Find more on Deployment, Integration, and Supported Hardware in Help Center and File Exchange

Products


Release

R2016b

Community Treasure Hunt

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

Start Hunting!