Possible bug in Negating a Boolean Input to a Stateflow
1 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(1 个)
Jorge Calvo
2021-11-2
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 https://www.mathworks.com/help/stateflow/ug/supported-operations-on-chart-data.html.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulink Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!