Introduction to Simulink
Simulink is MATLAB's graphical, block-diagram environment for modeling, simulating, and analyzing dynamic systems: instead of writing sequential code, you connect blocks representing signal sources, mathematical operations, dynamic elements, and outputs with lines that carry signals between them. This model-based design approach makes the structure of a system — how signals flow and transform over time — visually explicit, and it's the standard tool for simulating control systems, physical plants, and embedded logic before deploying to real hardware.
Cricket analogy: A Simulink block diagram modeling a bowling machine's speed-feedback loop is like a coach's tactical whiteboard, where boxes and arrows represent each stage of a strategy rather than a written procedural playbook.
Building Block Diagrams
You build models by dragging blocks from the Simulink Library Browser: Source blocks (Sine Wave, Step, Constant, Pulse Generator) generate signals, Sink blocks (Scope, Display, To Workspace) consume or display them, and functional blocks (Gain, Sum, Transfer Fcn) transform signals in between. When a group of blocks represents a reusable sub-function — say, a sensor-filtering stage — you can select them and convert them into a Subsystem, collapsing them into a single block with its own input/output ports, much like grouping code into a function.
Cricket analogy: Dragging a Sine Wave source block to simulate a bowling machine's oscillating release angle, then connecting it to a Scope sink block, mirrors setting up a bowling machine and immediately reviewing its delivery pattern on a monitor.
Signals, Subsystems, and Simulation Configuration
The solver you choose — fixed-step (e.g., ode3, ode4) or variable-step (e.g., ode45) — and the sample time it uses determine how the simulation advances through time, with fixed-step solvers taking uniform time increments (important for real-time or hardware-deployed simulations) and variable-step solvers adaptively refining the timestep to maintain accuracy where signals change rapidly. These settings live in the Model Configuration Parameters dialog and directly affect both simulation accuracy and how closely the simulated timing matches how the model will eventually run on real hardware.
Cricket analogy: Choosing a fixed-step solver to simulate ball trajectory at a constant 1ms timestep mirrors a stump-camera system capturing frames at a fixed frame rate rather than only when something interesting happens.
Algebraic loops — where a block's output feeds back into its own input within the same time step with no delay — can cause Simulink to fail to solve the model or silently produce incorrect results; insert a Unit Delay or Memory block to break the loop, or let Simulink's automatic loop-solving handle it explicitly.
Simulating and Analyzing Results
Running a model with sim('modelName') from the command line (or clicking Run in the toolbar) executes the simulation, with Scope blocks providing live visualization during the run and To Workspace blocks exporting signal time-series data as variables for post-processing in MATLAB. For comparing results across multiple runs — say, testing different controller gains — the Simulink Data Inspector logs and overlays signals from separate simulations without requiring you to add extra Scope blocks to the model itself.
Cricket analogy: Running sim('bowlingModel') and piping the output to a To Workspace block mirrors exporting a match's ball-by-ball data into a spreadsheet for post-match analysis by the team analyst.
The Simulink Data Inspector (accessible via the toolbar or Simulink.sdi.view) lets you log, compare, and overlay signals from multiple simulation runs without adding extra Scope blocks — invaluable when tuning parameters and comparing before/after behavior.
% Open a Simulink model and configure it programmatically
open_system('bowlingModel');
set_param('bowlingModel', 'StopTime', '10');
set_param('bowlingModel/Sine Wave', 'Amplitude', '5', 'Frequency', '2');
% Run the simulation and capture logged signals
simOut = sim('bowlingModel');
logsout = simOut.get('logsout');
speedSignal = logsout.getElement('BallSpeed');
plot(speedSignal.Values.Time, speedSignal.Values.Data);
xlabel('Time (s)'); ylabel('Ball Speed (m/s)');- Simulink models represent dynamic systems as block diagrams, connecting Source, Sink, and functional blocks with signal lines instead of sequential code.
- Subsystems group related blocks into a single reusable, collapsible unit, similar to functions in script-based MATLAB.
- Solver choice (fixed-step vs. variable-step) and sample time determine how the simulation advances through time and affect accuracy versus speed.
- Algebraic loops (zero-delay feedback) can prevent a model from solving and should be broken with a Unit Delay or Memory block.
- Scope blocks give real-time visualization during simulation, while To Workspace blocks export signals for post-processing in the MATLAB workspace.
- The Simulink Data Inspector lets you log and compare signals across multiple simulation runs without modifying the model.
- Models can be controlled programmatically from MATLAB using
open_system,set_param, andsim, enabling scripted parameter sweeps and automated testing.
Practice what you learned
1. What is the primary purpose of a Subsystem block in Simulink?
2. What is an algebraic loop in Simulink, and why is it problematic?
3. Which MATLAB function starts a Simulink simulation programmatically from a script?
4. What is the key difference between a Scope block and a To Workspace block?
5. What tool would you use to overlay and compare signals from two different Simulink simulation runs without adding extra Scope blocks?
Was this page helpful?
You May Also Like
MATLAB Toolboxes Overview
A tour of MATLAB's major add-on toolboxes — what they add on top of base MATLAB, when to reach for each one, and how to check what's installed and licensed.
Object-Oriented Programming in MATLAB
Learn how MATLAB's classdef syntax lets you bundle data and behavior into classes, using properties, methods, inheritance, and encapsulation to build maintainable, reusable code.
Debugging and Profiling MATLAB Code
Practical techniques for finding correctness bugs with MATLAB's interactive debugger and finding performance bottlenecks with the Profiler.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics