How can I save the state of one Simulink Compiler simulation and continue it in another session?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
MathWorks Support Team
il 13 Nov 2023
Risposto: MathWorks Support Team
il 13 Nov 2023
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
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, ...
"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
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Run Individual Simulations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!