Is there a way to represent an #ifdef statement in a simulink model?

26 views (last 30 days)
I am using Matlab 2018b, and i'm trying to create a simulink diagram based off of some c code. Though simulink has an "If" statement block, it doesn't appear to have a block for #ifdef statements.
Is there anyway to represent #ifdef statements in Simulink?

Accepted Answer

Walter Roberson
Walter Roberson on 22 Mar 2019
Edited: Walter Roberson on 22 Mar 2019
Simulink has conditionals, and Simulink has triggered subsystems, but those require that the control variable be defined (but can differentiate between various values.)
To do an #ifdef you would probably need to have a MATLAB Function block that somehow tested whether that entity was "defined" ... whatever "defined" means in this context. For example with rapid acceleration turned off, the MATLAB Function Block could probably use something like
evalin('caller', 'exists(''NAME'', ''var'')')
You would then use that to as a definite signal controlling something.
However, a lot of the time #ifdef is for blocks of code compensating for different operating systems interfaces, or differences in compilers, and those kinds of things should not generally be emulated at the Simulink level. It might make some sense to want to emulate #ifdef about which interface device to use, but if so then at the Simulink level that would probably be better handled as an defined parameter with different values to control what gets invoked.

More Answers (0)

Categories

Find more on Simulink Functions 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!