Code Generation: Static local variables

4 Ansichten (letzte 30 Tage)
Steg
Steg am 21 Nov. 2011
Kommentiert: sai ganesh am 26 Apr. 2024
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

Akzeptierte Antwort

Kaustubha Govind
Kaustubha Govind am 22 Nov. 2011
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.
  6 Kommentare
Sai Manga Reddy Karri
Sai Manga Reddy Karri am 30 Jul. 2021
I am trying to generate it for unit delay block..it is generated as global static.. but i am unable to generate it as local static..
sai ganesh
sai ganesh am 26 Apr. 2024
Any solution for this scenario? Even in MATLAB 2022b we are unable to generate the Block states as local static variables.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Fan BU
Fan BU am 26 Mai 2017
Please try using the block delay, the delayed signal will be one from last cycle, this corresponds to static in C code, see the picture, the signal rpmDir in generated C code will be static.
Maybe custom storage class is better solution, I never used this.

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by