MATLAB For Beginners: 20-Minute Video Training Course. (Grab The Training Course and The Cheat Sheet for FREE)

       

In this article, you will learn:

  • How to run a Simulink model from MATLAB
  • How to set up the simulation time of your model from MATLAB

Run a Simulink Model With the sim Command

Let us say we have the following model: 

You can run a Simulink model from MATLAB using the sim command:

% name of your model
modelName = 'mySimpleModel';
 
% sim will simulate the model in argument
sim(modelName);

Set up the Desired Simulation Time from Matlab

If you want to set up the duration time of your simulation from MATLAB, you can add a variable in your simulink model: 

Then, you can define this variable in your workspace or m file and run the simulation again as the following:

% time defines in seconds
t = 5;
modelName = 'mySimpleModel';
sim(modelName);

Leave a Reply