How do I make the generated model data structure "RT_MODEL" have a name unique to the model/subsystem name in MATLAB R2025b?

I have a model in Simulink R2025b that consists of multiple subsystems. I am generating code for each subsystem separately. When the code is generated by Embedded Coder, each subsystem produces a pointer variable for the model:
RT_MODEL *const rtM = &rtM_;
However, each subsystem has the same definition for this model pointer variable. Is it possible to generate code so that each subsystem would have a unique model pointer variable name? For example:
RM_MODEL *const rtM_subsystem1 = &rtM_subsystem1;

 Accepted Answer

Please check the setting under Model Configuration > Code Generation > Identifiers > Global Variables.
It may be set to something like "rt$N$M" by default, which is why all the subsystems generate with the same pointer variable. The "$R" token represents the root project/subsystem name, so if you set the value for that setting to "$R$N$M", the generated code should use the subsystem name for the pointer variable.
You can refer to the Customize Generated Identifiers documentation for more details on how to further customize the generated variable names. 

More Answers (0)

Categories

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

Products

Release

R2025b

Community Treasure Hunt

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

Start Hunting!