Set simulation time and fixed step size for a Simulink model from the command line

645 vues (au cours des 30 derniers jours)
Hi! I have a simulink model that I need to simulate over a few different durations and with a fixed (but different) sampling time. So what I want to do is to set this from the command line without having to start up simulink and change it manually each time.
To clarify I want to set the simulation duration (or the start time/stop time) and the solver options to Fixed-step (or at least change the step-size). So it would look something like this in a script/the command line:
sim('simModel', 'simulationTime', [0 10], 'solverOptions.stepSize', 1/1024)
Where 'simModel' is the simulink model in question.
It doesn't have to look like this, but just to give you an idea of what I want to do. Is there a way to do this?
I can't really find it in the documentations, the only thing I find is how to set the sampling time for a specific block, but I want to keep those as inherited.

Réponse acceptée

Sebastian Castro
Sebastian Castro le 12 Nov 2015
If you open the model's Configuration Parameters, for each parameter you can right-click and select "What's This?". This will open up some documentation, which includes a table that shows you how to programmatically use that parameter.
So, you can take that and use it in the sim command as you specified:
>> sim('modelName','StartTime','0','StopTime','10','FixedStep','0.2');
Notice that the properties have to take a string value and not a numeric value. This is where the num2str function comes in handy. For example,
for Ts = 0.01:0.01:0.1
simout = sim('modelName','FixedStep',num2str(Ts));
end
- Sebastian
  5 commentaires
mehdi azari
mehdi azari le 25 Fév 2021
I want to change the simulation time from seconds to minutes and hours. How should I do this?
Walter Roberson
Walter Roberson le 23 Avr 2022
The stop time always have to be passed to simulink in seconds; https://www.mathworks.com/help/simulink/gui/stop-time.html
If you have hours and minutes then
st_secs = seconds( hours(NumberOfHours) + minutes(NumberOfMinutes) );
num2str(st_secs)
or
st_secs = seconds( duration(NumberofHours, NumberOfMinutes, 0) )
num2str(st_secs)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Simulink dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by