MATLAB Answers

0

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

Asked by Meena Farag on 22 Mar 2019
Latest activity Edited by Walter Roberson
on 22 Mar 2019
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?

  0 Comments

Sign in to comment.

1 Answer

Answer by Walter Roberson
on 22 Mar 2019
Edited by Walter Roberson
on 22 Mar 2019
 Accepted Answer

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.

  0 Comments

Sign in to comment.