Why does running a simulation with saved initial states and changed sorted order lead to incorrect simulation behavior in Simulink?

1 view (last 30 days)
I have a model that uses states saved from a previous simulation of the same model. The only change I have made is disconnecting a Display block. When I run the model, it does not simulate as before. However, if I reconnect the Display, block the simulation runs as expected. I am not sure why disconnecting a Display block would make such a difference.
I have observed that disconnecting the Display block changes the sorted block execution order.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This enhancement has been incorporated in Release 2006b (R2006b). For previous product releases, read below for any possible workarounds:
This problem results from the fact that the initial states have been saved as an array. When the Display block is disconnected, the sorted order changes. However, when the model is run, it always uses the same number of states and assumes that sorted block execution order has not changed. This causes Simulink to assign the first state the first value, and so on. Since the sorted order changed when the Display was disconnected, the states no longer match up properly, which can lead to a simulation error.
To resolve this issue in Simulink 6.2 (R14SP2) and later, open the model with the Display block connected and execute the following command at the MATLAB prompt:
xInitial = sl('getInitialState','validate_new_method_working')
This will get the initial state structure and overwrite the old one, which was only a vector.
Note that in general it is a good idea to save the final states from a simulation as a "Structure" or "Structure with time", instead of an "Array", to avoid potential state mismatches.

More Answers (0)

Categories

Find more on Event Functions 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!