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

5 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

MathWorks Support Team
MathWorks Support Team il 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, ...
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));
%% 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.yout{1}.Values

Più risposte (0)


Non è stata ancora inserito alcun tag.

Community Treasure Hunt

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

Start Hunting!

Translated by