Search code examples
matlabsimulink

MATLAB: Specify Simulink simulation time using code


I want to run Simulink simulation from a script, and I can do it using:

sim('MobileRobotSimulation')

However, I would like to specify the time of the simulation. I wonder how I can achieve this.

Thanks in advance.


Solution

  • As I found in this link, it is possible to specify the simulation time using the following code:

    set_param(model_name, 'StopTime', '20')
    

    so in this case the simulation time is 20 seconds, and model_name = 'MobileRobotSimulation'.