Effacer les filtres
Effacer les filtres

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

30 vues (au cours des 30 derniers jours)
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?

Réponse acceptée

Walter Roberson
Walter Roberson le 22 Mar 2019
Modifié(e) : Walter Roberson le 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.

Plus de réponses (0)

Catégories

En savoir plus sur Subsystems dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by