MATLAB: How to generate code for masked subsystem such that I can see the its parameters initialized, when using Real Time Workshop 7.6 (R2010b)

simulink coder

I am using a masked subsystem block in my Simulink model for which I have masked subsystem block parameters. I provide values for those and then generate code.
But, I cannot see the values being initialized in the generated code initialize block.

Best Answer

You can do following steps to see the subsystem block parameters initialization in your generated code when using Real Time workshop 7.6 (R2010b).
1. When using the masked subsystem block in a simulink model and using a signal name under the mask, if you would like to include the signal name in the generated code perform the following steps:
a. Right click the signal name under the mask, select 'Signal Properties'.
b. In the new window, select the Real Time Workshop tab and in the 'Package' option select Simulink. You can select the 'Storage Class' type to SimulinkGlobal.
c. Save these changes
2. In the top level model window, select the Configuration Parameters. Here you need to uncheck the 'Block Reduction' and 'Inline Parameters' options in the Optimization option.
3. In order to have a single code file generated after the 'Generate Code' step, you need to make changes in the 'Code Placement' settings in the Real Time Workshop option in the 'Configuration Parameters'. In the settings, select the 'compact' option in the 'Code Packaging' option.
4. Build your model after this step.
5. In the generated code, you can see the signal name declared as a variable which is set to a default value in the model initialize block. This value updates when a function call is made such that the variable gets updated.
I have attached a model example 'masking_sample_example.mdl' to this email with all the above settings enabled. You can generate code for this model by using the Ctrl+B shortcut and see the generated code.