MATLAB: Code Generation: Static local variables

Embedded Coderrtw

I would like the "Block signals" and "Block states" in the generated c-code to be of the type "static".
Example:
static BlockIO_model B;
How do I get there? thx

Best Answer

I don't think there is currently a simple solution for this (I would recommend putting in an enhancement request with MathWorks Tech Support if this is important for your use-case).
However, this is certainly possible with use of Custom Storage Classes. You can create your own storage class to declare data as "static" in the generated code. This storage class can then be applied to data in your model by the use of Simulink.Signal (or mpt.Signal) and Simulink.Parameter (or mpt.Parameter) objects that use this as their storage class. There are some usage examples in the documentation section Types, Operators, and Expressions.