MATLAB: How to incrementally save output data from long Simulink simulation

logginglong simulationlpv systemsimulink

Hey everyone,
I'm using Simulink to compute the response of a linear, parameter varying system (LPV system). Within the simulation 24h data shall be generated with a sample frequency of 800 Hz. I'd like to save the output incrementally every 10 minutes.
My question is: How can I perform these blockwise savings?
Thanks
Stefan

Best Answer

You can specify the start and stop time of the simulation. The key point is to save the final state of the last simulation and use it as the initial state of the next simulation. Below is an example, you can change the loop number and insert the save command inside the loop to save your data.
vdp;
tStart='0';
tStop='10';
out=sim('vdp','StartTime',tStart,'StopTime',tStop,...
'SaveFormat','Structure',...
'SaveFinalState','On','FinalStateName','xFinal');
for k=1:1
tStart=tStop;
tStop=num2str(10+k*10);
x0=out.xFinal;
out=sim('vdp','StartTime',tStart,'StopTime',tStop,...
'SaveFormat','Structure',...
'LoadInitialState','On','InitialState','x0',...
'SaveFinalState','On','FinalStateName','xFinal');
end