"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!