MATLAB Answers

0

For code generation problem

Asked by Xiaoling Chen on 12 Sep 2015
Latest activity Answered by Jeevan Thomas on 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?

  0 Comments

Sign in to comment.

2 Answers

Answer by Jeevan Thomas on 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.

  0 Comments

Sign in to comment.


Answer by Walter Roberson
on 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.

  0 Comments

Sign in to comment.