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 statecorresponding 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
Best Answer