How to fix error in Simulink "data read before being written to" ?
61 views (last 30 days)
Show older comments
I get this message when I try to run my simulation of a simple elevator system. How can I fix this?
2 Comments
Answers (2)
Fangjun Jiang
on 25 Jun 2018
If you don't care that much, go to Model Configuration Parameters (Ctrl+E), Diagnostics, Stateflow, Read-before-write to output in Moore chart, change the setting.
0 Comments
Dalton L'Heureux
on 18 Nov 2022
I know this is an old post now, but figured I'd provide an answer incase anyone else runs into this. The statemachine captured in the image defualts into the Hold state. On the next time step, the first thing the statemachine is going to do is check its first priority transition from Hold to ReadKeyboard2. This condition is "[button < 0 && position > 0]." By just looking at the chart, I can't tell how the symbols "button" and "position" have been defined, but the error is telling us that at least the "position" symbol has not been initialized at the point at which Stateflow is trying to evaluate this condition. This means the value of "position" coud be anything... something stored in the memory location of a previous simulation perhaps... an untrustworthy value in otherwords. In the chart, the "position" symbol does not get explicitly defined until the statemachine enters the RunMotor state. The fix is to simply make sure all the symbols used in the statemachine are properly initialized (whether that be done internally within, or externally to the chart doesn't matter).
0 Comments
See Also
Categories
Find more on Complex Logic in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!