For code generation problem

4 Ansichten (letzte 30 Tage)
Xiaoling Chen
Xiaoling Chen am 12 Sep. 2015
Beantwortet: Jeevan Thomas am 15 Sep. 2015
When generation code for the attachment model, i find that the united delay block is generated as reachable variables in .h file, as is shown in the attachemnt figure. My question is, if we want to configure the united delay block as globale variables, but without the "extern" word, how to do this?

Antworten (2)

Jeevan Thomas
Jeevan Thomas am 15 Sep. 2015
If you want to generate the unit delay variable in the model as a global variable, but not as an extern variable means that you would like to configure the unit delay as a static variable (with no declaration in the H file, but scope only in the C file). Open the unit delay block and give a unique name to the state attributes. Then as shown in figure, check the "state must resolve to simulink signal" box.
Now you must create a Simulink.Signal object of the same unique identifier in the Matlab workspace and set the storage class as "FileScope". This tells the code generator that the resolved signal is restricted only to a single file. So extern declarations are not required. Eg: UD = Simulink.Signal; UD.StorageClass = 'FileScope (Custom)'
Build the model/Generate code. You'll find that the delay block is now generated as variable "UD" and it's declared on top of the C file as static.
Hope it helps.

Walter Roberson
Walter Roberson am 12 Sep. 2015
"extern" is C's method for noting global variables. "extern" in C is equivalent to "global" in MATLAB, except for some issues having to do with initializing. If you had something in C that did not use "extern" then it would not be a global.

Kategorien

Mehr zu Simulink Coder finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by