How can I save the state of one Simulink Compiler simulation and continue it in another session?

2 Ansichten (letzte 30 Tage)
I would like to save the state of a simulation in one Simulink Compiler session and load the simulation state in another Simulink Compiler session. So for example, I run the deployed simulation once, it simulates to time t=10. Then I open the deployed simulation again and run it, and the simulation continues from where the previous run left off. So simulating from t = 10 to t = 20. Is this possible?

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 13 Nov. 2023
Yes, you can save an Operating Point to file from a deployed application. Then you can load this file in the next session of your deployed application and load the Operating Point into your model. See the attached example for details.
The code is also pasted below:
%% Set simulation input
mdl = 'vdp';
simIn = Simulink.SimulationInput(mdl);
simIn = setModelParameter(simIn, ...
"SaveFinalState","on","SaveOperatingPoint","on");
simIn = simulink.compiler.configureForDeployment(simIn);
%% If the operating point file exists, load it
if isfile('xFinal.mat')
load xFinal.mat
simIn = setInitialState(simIn, xFinal);
simIn = setModelParameter(simIn, "StartTime", string(xFinal.snapshotTime));
simIn = setModelParameter(simIn, "StopTime", string(xFinal.snapshotTime+10));
end
%% Setup a model input
testData = Simulink.SimulationData.Dataset;
testData.Name = 'testData';
testData = testData.addElement(timeseries([0,20], [0,20]));
simIn = simIn.setExternalInput(testData);
%% run model
simOut = sim(simIn);
%% Save the operating point or later use
xFinal = simOut.xFinal;
save xFinal xFinal
save simOut simOut
simOut.data = simOut.yout{1}.Values

Weitere Antworten (0)

Kategorien

Mehr zu Run Individual Simulations finden Sie in Help Center und File Exchange

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by