"Cannot find state N in the given variable." Error when trying to start a simulation using previously saved states.
4 views (last 30 days)
I am using Simulink to simulate a large model, that includes S functions.
I am using R2018a and I am saving the states at the end of a simulation using the Dataset format.
R2018a does not support 'SaveOperatingPoint' so I am just saving the states, not the whole operating point.
When I try to run the next simulation, by loading the states (using set_param(model, 'LoadInitialState', 'on'); before the run), I am getting the following error which I am not sure how to address:
Cannot find state 339 in the given variable.
Component:Simulink | Category:Model error
How can I find out which block, or part of the model, is causing this?
I have some S functions, in which I have enabled the mdlGetSimState() and mdlSetSimState() methods, which seem to be working correctly.
I have also included the relevant calls to:
which seem to compile correctly.
I have the option to try again with MATLAB/Simulink R2021b, which I can try tomorrow. The mdlGetSimState() and mdlSetSimState() methods will then become mdlGetOperatingPoint() & mdlSetOperatingPoint(), and ssSetSimStateVisibility(S, 1U); will be replaced by ssSetOperatingPointVisibility (S, 1U);. I can then also TRY with 'SaveOperatingPoint' set ON as well. But, I am not feeling confident that this will solve the problem. I suspect it will remain.
How can I locate the source of the "Cannot find state 339 in the given variable." error?
Fangjun Jiang on 9 Jun 2022
set_param(model, 'LoadInitialState', 'on') just turns on that checkmark, you need to provide the variable for the initial state.
Do it manually first, at Configuration Parameters, Data Import/Export, turn on "Final States" "xFinal", run one simulation.
Next, specify the "Initial state" as "xFinal" and run simulation again.
In between, you can check if "xFinal" has all the states. It looks like you have a lot of states. Make sure all S-functions have their states properly defined.