simulink/simscape final state 'cannot find a matching block state to element 135' output by the same model
古いコメントを表示
I have a model that contains some simulink and simcape model.
The gist is: initail simulation from T0 to T1, perfrom some analysis, then restart at T1 and run to T2, etc. But this breaks when restarting T1. Kindly note: This intermediate analysis affects workspace parameters that affect values of e.g. electrical resistances in the model.
cset = getConfigSet( gcs, 'Configuration1' );
set_param(cset, 'Solver','VariableStepAuto')
set_param(cset, 'SolverName','VariableStepAuto')
set_param(cset, 'LoadInitialState','off');
set_param(cset, 'StateSaveName', 'state_history');
set_param(cset, 'SaveFinalState','on')
set_param(cset, 'FinalStateName','xFinal')
set_param(cset,'StartTime', string(T0) );
set_param(cset,'StopTime', string(T1) );
simOUT = sim( gcs, cset );
assignin('base','xFinal',simOUT.get('xFinal'))
set_param(cset, 'LoadInitialState','on')
set_param(cset,'InitialState', 'xFinal')
set_param(cset,'StartTime', string(T1) );
set_param(cset,'StopTime', string(T2) );
simOUT = sim( gcs, cset );
The first run is fine. everything looks fine. The second model call yields:
Unable to load the specified initial state for model 'your_model'. Cannot find a matching block state
corresponding to element 135 of signals structure array.
Nothing has changed in the model, and the error sound like as if a block has simply vanished.
This is field is present in the first run's output:
simOUT.xFinal.signals(135)
ans =
struct with fields:
values: 16.6848539456316
dimensions: 1
label: 'CSTATE'
blockName: 'your_model/comp1/C'
stateName: 'your_model.comp1.C.p.v'
inReferencedModel: 0
and is the exact same thing stored in 'xFinal' that's parsed to the model workspace and pushed as an initial state.
I'm wondering if restarting models with simscape elements need further considerations than those shown in : https://www.mathworks.com/help/simulink/slref/saving-and-restoring-simulation-operating-point.html
採用された回答
その他の回答 (1 件)
Fangjun Jiang
2020 年 9 月 15 日
0 投票
This is frustrating! Try this, note the difference between 'Save complete SimState in final state' and 'Save Final States'
2 件のコメント
Fangjun Jiang
2020 年 9 月 16 日
Maybe you should consider a different approach. Use set_param(Model,'SimulationCommand','Pause') to pause the simulation, change parameters, update model and then continue the simulation. The pause can be triggered by a callback function of a block in the model, which compares the clock with T1.
カテゴリ
ヘルプ センター および File Exchange で Nonlinear Operators についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

