Skip to content
Tutorials Center
My learning

Topics

Lesson 2 of 36 ยท Getting Started

Your First Simulink Model: Interface, Library Browser and Scope

Build your first Simulink model step by step: start Simulink, open the Library Browser, place a Sine Wave and Scope, connect the ports and run the simulation.

The best way to learn Simulink is to build something tiny and run it. In this lesson you will create the classic first model: a Sine Wave source connected to a Scope sink. Along the way you will meet the Simulink editor, the Library Browser and the basic mouse and keyboard moves you will use in every model.

Simulink is not available on this site, so the steps below describe the real product. Each step has a Python stand-in that shows what the model computes. Menu names follow current releases (R2022a and later); older releases look slightly different, but the ideas are the same.

  1. Start MATLAB.
  2. Type simulink in the Command Window, or click Simulink on the Home tab. The Simulink Start Page opens.
  3. Under Simulink, choose Blank Model. A new editor window appears with an empty canvas, named untitled.

You can also create a model from the command line with new_system('mymodel'); open_system('mymodel'), which we cover in Simulink from MATLAB Scripts.

The editor window

  • Canvas: the large white area where you place blocks.
  • Toolstrip tabs: Simulation (run, stop, stop time), Debug, Modeling (model settings, subsystem tools), Format (colors, annotations), Apps.
  • Quick Access toolbar: save, undo, redo, library browser and run.
  • Status bar at the bottom: shows the solver, zoom level and simulation status. The model browser can be opened from the left edge.

The Library Browser

Click Library Browser on the Simulation tab (or type slLibraryBrowser in MATLAB). Blocks are grouped in libraries such as Commonly Used Blocks, Sources, Sinks, Math Operations, Continuous, Discrete and Signal Routing. Use the search box to find a block by name.

There is a faster way: double-click an empty spot on the canvas and start typing a block name (for example sine). Press Enter to place the first match at that position.

Build the model

  1. Double-click the canvas, type Sine Wave, choose the block from Sources, and place it on the left.
  2. Do the same with Scope (found in Sinks) and place it to the right.
  3. Move the pointer over the output arrow on the right side of the Sine Wave block. The cursor turns into a cross. Drag to the input port of the Scope. A line with an arrowhead appears. (A faster move: select the first block, hold Ctrl and click the second block to connect them automatically.)
  4. Save with Ctrl+S as first_model.slx.

Block ports are the small triangles on a block's sides. Inputs are on the left, outputs on the right, unless you flip the block.

Build the first model

Place Sine Wave From Sources
Place Scope From Sinks
Connect ports Drag a line
Run Ctrl+T

Four moves are enough for a working model.

1 / 2

Set parameters and run

Double-click the Sine Wave block to open its parameter dialog. The defaults are Amplitude 1, Bias 0, Frequency 1 (rad/sec), Phase 0 and Sample time 0 (continuous). Change Frequency to 2 and click OK.

Set the Stop time on the Simulation tab to 10 (the default) and click Run or press Ctrl+T. When the simulation ends, double-click the Scope. You see a curve that oscillates between -1 and 1 and completes about 3.18 periods over 10 seconds, because the period is 2ฯ€/2 โ‰ˆ 3.14 s.

Right-click a block and choose Format > Show Block Name, or use the Format tab to change colors, flip or rotate blocks. A neat diagram is easier to read and to review.

What the model computes

At every time step the Sine Wave block outputs amplitude * sin(frequency * t + phase) + bias, and the Scope displays that value against time. Here is the same calculation as a stand-in.

Python Stand-in: Sine Wave to Scope (Python)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The printed bars play the role of the Scope trace. In Simulink the solver chooses the step size itself unless you fix it (see Simulation Time and Solvers).

Customizing the Scope

Double-click the Scope to open the viewer. Useful toolbar items:

  • Settings (gear): number of input ports (layout), time span, axis limits.
  • Autoscale (the binoculars icon with arrows): fits the vertical axis to the data.
  • Cursor measurements and Peak Finder from the Measurements section.
  • Legend: shows signal names if you name the lines (click a line, type a name).

Naming signals by double-clicking the line and typing a label is a habit worth forming early: the name is carried into logs and generated code.

Common first-model mistakes

Symptom Cause
Line is dashed red Ports are not actually connected; drag the line end onto the port
Warning "unconnected input port" A block input has nothing attached; terminate it with a Constant or Terminator
Scope is empty You did not run the simulation, or the Scope window was opened before the run finished
Curve looks jagged The step size is too large; reduce Max step size

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. How do you quickly add a block without opening the Library Browser?

    Double-clicking an empty spot on the canvas opens a search box that places the chosen block.
  2. 2. Which shortcut starts a simulation?

    Ctrl+T starts the simulation; Ctrl+E opens the model settings.
  3. 3. What does the Sine Wave block output with Amplitude 3, Bias 1 and Frequency 1 at t = 0?

    At t = 0 sin(0) = 0, so the output is 3 * 0 + 1 = 1 (the bias).
  4. 4. Where are the input ports of a block normally located?

    Inputs are on the left and outputs on the right unless the block is flipped or rotated.

Summary

  • Start Simulink with the simulink command or the Home tab and choose Blank Model.
  • Place blocks from the Library Browser or by double-clicking the canvas; connect output ports to input ports.
  • Ctrl+T runs the model, and the Scope displays signals against time.
  • Block dialogs hold parameters; Sine Wave outputs A*sin(w*t+phi)+bias.
  • Name your signals early; unconnected ports give warnings.

Next: Simulation Time and Solvers