#Define Preprocessor statements in Simulink Library File
7 views (last 30 days)
Show older comments
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?
Answers (1)
Chetna Jain
on 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!
See Also
Categories
Find more on Subsystems in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!