For code generation problem

3 vues (au cours des 30 derniers jours)
Xiaoling Chen
Xiaoling Chen le 12 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?

Réponses (2)

Jeevan Thomas
Jeevan Thomas le 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 le 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.

Catégories

En savoir plus sur Deployment, Integration, and Supported Hardware dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by