#Define Preprocessor statements in Simulink Library File
9 views (last 30 days)
Show older comments
DKalale on 7 Feb 2018
Commented: DKalale on 17 Feb 2018
After reading this mathworks support article, I would like to apply this to a set of Simulink Libraries:
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?
Chetna Jain on 16 Feb 2018
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
To understand "assignin" function , below mentioned is the link :
Hope this helps!
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!