Azzera filtri
Azzera filtri

Possible bug in Negating a Boolean Input to a Stateflow

11 visualizzazioni (ultimi 30 giorni)
I am building a model in 2017A, and spent a few days hunting down what I thought was a logic bug in my code, but now looks like a Simulink/Stateflow error that I have been able to reproduce in a much simpler model. Since I was unable to attach that model, it should be reproducible from these screen-shots...
...and inside the Stateflow...
You can run this model, switch the switch a few times, and see that it runs as expected, with the Boolean value simply passing through the Stateflow block. However, change the command line within the Stateflow to "{Out = ~In;}", and I would expect the output to now be the opposite of the input. But instead I see that the output is always 1.
I resolved this issue in my main model by moving some of the Boolean logic outside of the Stateflow and implementing it in Simulink. It is less memory efficient that way, but it works. My question to the community is if this is a known problem (I could not find any reference to it in a brief search of the problem reports), and if not then to whom in MatLab should this be reported? Or am I just somehow misunderstanding how Booleans are supposed to be implemented in Stateflow?

Risposte (1)

Jorge Calvo
Jorge Calvo il 2 Nov 2021
Hi Jeremy,
I noticed that your chart uses C as the action language. In this case, ~In does a bitwise NOT (not a logical NOT) operation. To perform a logical NOT operation in C action language, you should use !In. Alternatively, change the action language of your chart to MATLAB. I think either of those actions should solve your problem.
For more information about the differences in syntax between the two action languages, see


Scopri di più su Complex Logic in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by