#Define Preprocessor statements in Simulink Library File
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
After reading this mathworks support article, I would like to apply this to a set of Simulink Libraries:
https://www.mathworks.com/matlabcentral/answers/184184-how-do-i-make-sure-simulink-constants-are-coded-as-define
However, it seems that libraries do not have options that this article points to (at least I cannot find them). Is there a way in the model explorer to define a custom type that creates a #define statement with a constant that generates to C code with a preprocessor #define statement?
4 Commenti
Chetna Jain
il 13 Feb 2018
Hi,
I am unable to understand what “options ” are you referring to here. Perhaps on left most Model Hierarchy panel the “base workspace” is not selected and thus the options might be greyed out in Model Explorer.
Below mentioned link can be a good help if you still face issues or for further reference : https://www.mathworks.com/help/ecoder/ug/macro-definitions-define.html#bsi4as4-1
Risposte (1)
Chetna Jain
il 16 Feb 2018
Hi,
Try using "asignin" method to get the desired functionality.
In the InitFcn Callback of the library use "assignin(ws, 'var', val)".
This assigns the value val to the variable var in the workspace ws (here , ws = 'base')
This will enable the model which is using Subsytems from your library to view the data.
If the constant parameters are specific to a particular Subsystem in your library, you may instead use "assignin" function in the
Susbsystem's InitFcn Callback.
In this case, instead of putting var in model workspace, keep it in Subsytems InitFnc Callback.
For example, the Subsystem InitFcn would look something like :
kRootTwo = Simulink.Parameter
kRootTwo.Value = 1.414
assignin('base','kRootTwo', kRootTwo);
To understand "assignin" function , below mentioned is the link :
Hope this helps!
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!