This is an ideal application for a "ModelOperatingPoint" object. The "ModelOperatingPoint" object is a MATLAB object that stores information about the final state of the simulation at a given stop time. For this use case, that stop time is 10 seconds. You can then use the "ModelOperatingPoint" object to run the same model again but this time starting from the time-step and simulation state that was saved at 10 seconds till any new stop time you specify without losing the data that was generated during the initial run.
To get started on "ModelOperatingPoint", please refer to the following documentation link:
https://www.mathworks.com/help/releases/R2020b/simulink/ug/saving-and-restoring-simulation-operating-point.html
Below are two scripts, executed in sequence, that should execute the above required workflow for the attached example Simulink model called "vdpOperatingPointExample.slx". The attached model "vdpOperatingPointExample.slx" is a copy of one of the Simulink shipped examples called "vdp" that models the van der Pol equation. More resources on how to programmatically control and simulate the "vdp" shipped example can be found here:
https://www.mathworks.com/help/releases/R2020b/simulink/ug/using-the-sim-command.html
To demonstrate the use of model operating points for saving a model's operating point and re-starting the simulation from that point, first, download the attached model: "vdpOperatingPointExample.slx".
Then, in the same MATLAB working directory as the downloaded Simulink model, please execute the below script:
open_system('vdpOperatingPointExample')
set_param('vdpOperatingPointExample','InitialState','[]')
set_param('vdpOperatingPointExample','SaveFinalState','on','FinalStateName',...
'myOperPoint','SaveOperatingPoint','on');
simOut = sim('vdpOperatingPointExample','StopTime','10')
myOperPoint = simOut.myOperPoint
save('data','myOperPoint')
save_system('vdpOperatingPointExample')
Now you can close MATLAB and then execute the below script to extract the saved operating point and then start the simulation from time 10s:
open_system('vdpOperatingPointExample')
set_param('vdpOperatingPointExample','SaveFinalState','off',...
'SaveOperatingPoint','off');
load data
set_param('vdpOperatingPointExample','LoadInitialState','on','InitialState',...
'myOperPoint');
sim('vdpOperatingPointExample','StopTime','20')
set_param('vdpOperatingPointExample','InitialState','[]')
Best Answer