Bird
Raised Fist0
Simulinkdata~10 mins

Running a simulation in Simulink - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Running a simulation
Open Simulink Model
↓
Set Simulation Parameters
↓
Start Simulation
↓
Simulink Runs Model
↓
Collect Output Data
↓
Analyze or Visualize Results
↓
Stop Simulation
The flow shows opening a model, setting parameters, running the simulation, collecting data, and analyzing results.
Execution Sample
Simulink
sim('model_name')
% Runs the Simulink model named 'model_name'
% Collects output logged in workspace
plot(simout.time, simout.signals.values)
% Plots simulation output over time
This code runs a Simulink model and plots the output signal over time.
Execution Table
StepActionEvaluationResult
1Open model 'model_name'Model loadedModel ready for simulation
2Set simulation stop time to 10 secondsStop time setSimulation will run for 10 seconds
3Start simulation with sim('model_name')Simulation runningModel executes equations over time
4Simulink computes outputs at each time stepOutputs generatedOutput data stored in simout
5Simulation reaches stop timeSimulation stopsFinal output data available
6Plot output dataData plottedGraph shows signal vs time
💡 Simulation stops when time reaches the set stop time (10 seconds)
Variable Tracker
VariableStartAfter Step 3After Step 5Final
simoutundefinedpartial data during simulationcomplete data after simulationcomplete data after simulation
timeundefinedtime vector growingtime vector completetime vector complete
signal valuesundefinedvalues computed stepwisevalues completevalues complete
Key Moments - 3 Insights
Why does the simulation stop automatically after some time?
The simulation stops because the stop time parameter is set before running. See execution_table row 5 where simulation stops at 10 seconds.
What is stored in the variable 'simout'?
'simout' stores the output signals generated during simulation. It starts undefined and fills as simulation runs (see variable_tracker).
Why do we plot after simulation stops?
Plotting requires complete data. The simulation must finish to have full output data to visualize (see execution_table row 6).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step does the simulation actually start running?
AStep 3
BStep 1
CStep 5
DStep 6
💡 Hint
Check the 'Action' column for when sim('model_name') is called.
According to variable_tracker, what is the state of 'simout' after step 3?
AComplete data available
BPartial data during simulation
CUndefined
DData deleted
💡 Hint
Look at the 'After Step 3' column for 'simout' in variable_tracker.
If the stop time was set to 20 seconds instead of 10, what would change in the execution_table?
AStep 6 would be skipped
BStep 3 would not run
CStep 5 would say simulation stops at 20 seconds
DSimulation would stop immediately
💡 Hint
Refer to the exit_note and step 5 about simulation stop time.
Concept Snapshot
Running a simulation in Simulink:
1. Open your model.
2. Set simulation parameters (like stop time).
3. Run simulation with sim('model_name').
4. Simulink computes outputs over time.
5. Collect output data (e.g., simout).
6. Analyze or plot results after simulation ends.
Full Transcript
Running a simulation in Simulink involves opening a model, setting parameters such as stop time, and starting the simulation using the sim function. During simulation, Simulink computes outputs step-by-step and stores them in variables like simout. The simulation stops automatically when the stop time is reached. After simulation finishes, you can analyze or plot the output data to understand the system behavior.

Practice

(1/5)
1. What is the main purpose of running a simulation in Simulink?
easy
A. To test and analyze a model's behavior without building physical hardware
B. To write code faster
C. To create graphical user interfaces
D. To compile the model into an executable file

Solution

  1. Step 1: Understand simulation purpose

    Simulation allows testing how a model behaves in a virtual environment.
  2. Step 2: Compare options

    Only To test and analyze a model's behavior without building physical hardware describes testing and analyzing without physical hardware.
  3. Final Answer:

    To test and analyze a model's behavior without building physical hardware -> Option A
  4. Quick Check:

    Simulation = safe model testing [OK]
Hint: Simulation means testing model behavior virtually [OK]
Common Mistakes:
  • Confusing simulation with code writing
  • Thinking simulation creates GUIs
  • Assuming simulation compiles code
2. Which command correctly starts a simulation of a Simulink model named myModel?
easy
A. sim('myModel')
B. execute('myModel')
C. start_sim('myModel')
D. run('myModel')

Solution

  1. Step 1: Recall Simulink simulation command

    The correct command to run a simulation is sim('modelName').
  2. Step 2: Match command to options

    Only sim('myModel') uses sim('myModel') correctly.
  3. Final Answer:

    sim('myModel') -> Option A
  4. Quick Check:

    sim command runs simulation [OK]
Hint: Use sim('modelName') to start simulation [OK]
Common Mistakes:
  • Using run() instead of sim()
  • Trying start_sim() which is invalid
  • Using execute() which is not a Simulink command
3. Given the code:
out = sim('simpleModel', 'StopTime', '10');
disp(out.tout(end));

What will be displayed?
medium
A. 0
B. 10
C. Simulation error
D. Undefined variable

Solution

  1. Step 1: Understand sim command with StopTime

    The simulation runs from time 0 to 10 seconds.
  2. Step 2: Check output time vector

    out.tout stores simulation time points; end is last time point, which is 10.
  3. Final Answer:

    10 -> Option B
  4. Quick Check:

    Simulation end time = 10 [OK]
Hint: tout(end) shows simulation stop time [OK]
Common Mistakes:
  • Assuming output is 0 instead of final time
  • Expecting an error without cause
  • Confusing variable names
4. What is wrong with this code snippet to run a simulation?
sim('modelName', StopTime=20);
medium
A. The StopTime parameter is misspelled
B. The model name must be a variable, not a string
C. StopTime should be a string, not a variable
D. sim command cannot take parameters

Solution

  1. Step 1: Check parameter syntax for sim

    Parameters like StopTime must be passed as strings: 'StopTime', '20'.
  2. Step 2: Identify error in code

    Code uses StopTime=20 without quotes, causing syntax error.
  3. Final Answer:

    StopTime should be a string, not a variable -> Option C
  4. Quick Check:

    Parameter names and values must be strings [OK]
Hint: Use quotes for parameter names and values [OK]
Common Mistakes:
  • Passing parameters without quotes
  • Confusing variable and string types
  • Thinking sim can't take parameters
5. You want to run a simulation of controlModel from 0 to 15 seconds and save the output to variable simOut. Which code correctly does this and allows you to access the simulation output data?
hard
A. sim('controlModel', 'StopTime', 15, 'Output', simOut);
B. sim('controlModel', 'StartTime', '0', 'EndTime', '15');
C. simOut = run('controlModel', StopTime='15');
D. simOut = sim('controlModel', 'StopTime', '15');

Solution

  1. Step 1: Identify correct sim syntax for stop time and output

    Use sim('modelName', 'StopTime', 'time') and assign output to a variable.
  2. Step 2: Evaluate options

    simOut = sim('controlModel', 'StopTime', '15'); correctly assigns output to simOut and sets stop time as string '15'. Others have syntax errors or wrong commands.
  3. Final Answer:

    simOut = sim('controlModel', 'StopTime', '15'); -> Option D
  4. Quick Check:

    Assign sim output to variable with sim('model', 'StopTime', 'time') [OK]
Hint: Assign sim output to variable; use 'StopTime' as string [OK]
Common Mistakes:
  • Passing StopTime as number without quotes
  • Using run() instead of sim()
  • Incorrect parameter names like StartTime/EndTime
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard