Filter löschen
Filter löschen

Run Simulink repeatedly from Matlab

8 Ansichten (letzte 30 Tage)
Audrow Nash
Audrow Nash am 18 Jul. 2017
Kommentiert: Audrow Nash am 19 Jul. 2017
I am going to be running a simulation repeatedly varying a few parameters.
I will have to do hundreds of iterations. I do not want to compile every time. My Simulink contains external calls. Currently, the parameters that I will vary are put in the workspace by an initialization script.
What is the best practice for running simulations using Simulink repeatedly when modifying parameters from Matlab?

Akzeptierte Antwort

Sebastian Castro
Sebastian Castro am 18 Jul. 2017
The best approach is to use Fast Restart simulation: https://www.mathworks.com/help/simulink/ug/fast-restart-workflow.html
Fast restart will let you run simulations repeatedly without recompiling, as long as the variables you're changing do not affect the model in any way. For example, you can change tunable parameters, inputs, etc. but not structural things such as sample times, data types, dimensions, etc.
To do this from the command line, you can just do:
for idx = 1:100
myParams = externalFunction(idx);
simout = sim('modelName','FastRestart','on');
end
- Sebastian
  2 Kommentare
Audrow Nash
Audrow Nash am 19 Jul. 2017
Thank you.
Audrow Nash
Audrow Nash am 19 Jul. 2017
How does Fast Restart work with SimState?
The second step in your link says to save a SimState. When I try to save a SimState, I get the following error:
The following parameters are not supported by the sim command when Fast Restart is enabled: 'SaveFinalState, FinalStateName, SaveCompleteFinalSimState'
Here is a snippet of my code:
set_param(simulation,'FastRestart','on')
% Create a SimState at the final time of 0
% (as soon as the simulator starts)
simOut = sim(simulation,'StopTime','0',...
'SaveFinalState', 'on',...
'FinalStateName','xFinal',...
'SaveFormat','Structure');
% Adjust simulator over iterations
for i = 1:100
% Adjust parameters in the workspace
simOut1 = sim(simulation,'StartTime', ...
'0', 'StopTime', '5',...
'SaveFinalState', 'off', ...
'LoadInitialState', 'on', ...
'InitialState', 'xFinal');
end

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu General Applications finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by