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

1 次查看(过去 30 天)
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?

采纳的回答

MathWorks Support Team
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 个)

类别

Help CenterFile Exchange 中查找有关 Run Individual Simulations 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by