simulink/simscape final state 'cannot find a matching block state to element 135' output by the same model
Mostra commenti meno recenti
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
Risposta accettata
Più risposte (1)
Fangjun Jiang
il 15 Set 2020
0 voti
This is frustrating! Try this, note the difference between 'Save complete SimState in final state' and 'Save Final States'
2 Commenti
Fangjun Jiang
il 16 Set 2020
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.
Categorie
Scopri di più su Variable Initialization in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

