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

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

采纳的回答

Sebastian Castro
Sebastian Castro 2015-11-12
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 个评论
Walter Roberson
Walter Roberson 2022-4-23
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)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by