"Cannot find state N in the given variable." Error when trying to start a simulation using previously saved states.
3 次查看(过去 30 天)
显示 更早的评论
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:
ssSetSimStateCompliance(S, USE_CUSTOM_SIM_STATE);
ssSetSimStateVisibility(S, 1U);
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?
6 个评论
Fangjun Jiang
2022-6-10
If only small number of states need to be initilized and majority of the states take default or zero initial value, then using State Read/Write blocks might be easier.
回答(1 个)
Fangjun Jiang
2022-6-9
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!