Skip to content

MATLAB - Simulink

MATLAB - Introduction to Simulink for Model-Based Design

Section titled “MATLAB - Introduction to Simulink for Model-Based Design”

Simulink® is a MATLAB-based graphical programming environment for modeling, simulating, and analyzing multidomain dynamical systems. Its primary interface is a graphical block diagramming tool and a customizable set of block libraries. It offers tight integration with the rest of the MATLAB environment and can drive MATLAB or be scripted from it.

Simulink is widely used for automatic control and digital signal processing for multidomain simulation and Model-Based Design.

Core capabilities of Simulink include:

  • A graphical editor for building and managing hierarchical block diagrams.
  • Libraries of predefined blocks for modeling continuous-time and discrete-time systems.
  • Simulation engines (solvers) for solving differential equations that model the system’s behavior.
  • Scopes and data displays for visualizing simulation results.
  • Project and data management tools for organizing your work.

Key add-on products extend Simulink’s capabilities into specific domains:

  • Stateflow®: For modeling and simulating decision logic using state machines and flow charts.
  • Simscape™: For modeling and simulating multidomain physical systems (e.g., electrical, mechanical, fluid).
  • Simulink Coder™: For automatically generating C and C++ code from your models for real-time applications.
  • Embedded Coder®: Extends Simulink Coder with advanced optimizations for production embedded systems.
  • Simulink Test™: For automating the testing, verification, and validation of your models.

To open the Simulink start page, type the following command in the MATLAB Command Window:

simulink

The Simulink start page will open. It allows you to create new models from templates (like ‘Blank Model’) or open recent projects and models. For your first model, select ‘Blank Model’ and click ‘Create Model’.

This opens an empty, untitled model window (e.g., untitled.slx). This window is your canvas. You will also see the Library Browser, which contains all the blocks you can use to build your model.

Building a Simple Model: Simulating a Sine Wave

Section titled “Building a Simple Model: Simulating a Sine Wave”

A Simulink model is a block diagram. You build a model by adding blocks from the Library Browser and connecting them with signal lines. Let’s build a model that generates a sine wave and displays it in a Scope viewer.

The most efficient way to add blocks is to double-click on the canvas and start typing the block name.

  1. Double-click anywhere in the blank model window. A search box will appear.
  2. Type sine and select the Sine Wave block from the list that appears. Press Enter. The block is added to your model.
  3. Double-click on the canvas again. Type scope and select the Scope block. Press Enter.

You should now have two blocks in your model window: a ‘Sine Wave’ block, which is a Source (it generates a signal), and a ‘Scope’ block, which is a Sink (it displays a signal).

To send the signal from the source to the sink, you need to connect them.

  1. Hover your mouse over the right side of the ‘Sine Wave’ block until a small > symbol (an output port) appears.
  2. Click on the output port. A blue line will appear, following your cursor.
  3. Move your cursor to the left side of the ‘Scope’ block until its input port < is highlighted.
  4. Click on the input port to complete the connection. A solid arrow should now connect the two blocks.

The arrow indicates the direction of signal flow, from the Sine Wave generator to the Scope visualizer.

With the model complete, you can run the simulation. In the model window’s toolstrip, you will see a ‘Run’ button (a green play icon).

  1. Ensure the simulation stop time is set to a reasonable value, like 10.0 (the default). You can change this in the toolstrip.
  2. Click the Run button.
  3. The simulation will run quickly. To see the output, double-click the Scope block.

A new window titled ‘Scope’ will open, displaying a graph of a sine wave over a time axis from 0 to 10 seconds. You can use the tools in the Scope window to zoom, pan, and measure the signal.

  • MATLAB Function Block: For complex logic, you can embed your own MATLAB code directly into a Simulink model using the ‘MATLAB Function’ block. This is extremely powerful for combining algorithmic code with system-level models.
  • Simulink Projects: For any non-trivial project, use Simulink Projects (.prj files) to manage all related files (models, scripts, data). This helps with path management, source control integration, and sharing your work with others.
  • Version Control: Simulink models saved in the modern .slx format are easier to manage with version control systems like Git. The .slx file is a compressed package containing XML files, which allows for better diffing and merging than the old binary .mdl format.