Main Content

Connect Blocks

Establish relationships between the blocks in your model by connecting them.

You can connect most blocks using signal lines.

Signal lines connect to ports on blocks. During simulation, signals travel from output ports to connected input ports.

  • You can send the signal from the output port of one block to the input ports of multiple blocks by branching the signal line.

  • For some blocks you can change the number of input ports on the block. For example, to plot multiple signals on the same graph, you can increase the number of input ports on the Scope block.

For information about changing signal line layout, see Configure Model Layout.

You can simplify your block diagrams by bundling signals. For information about bundling signals, see Group Signals or Messages into Virtual Buses.

Related blocks connect without signal lines. For information about how to connect related blocks, see Connect Blocks Without Signal Lines.

Connect Blocks with Signal Lines

To connect two blocks with a signal line, click and drag the port symbol Port Symbol at the output port of one block to the input port of the other block.

A Sine Wave block is to the left of a Gain block. They are not connected. The output port of the Sine Wave block and the input port of the Gain block face each other and are labeled. The output port is on the right side of the block, and the input port is on the left side of the block.

You can use these shortcuts to connect blocks:

  • To connect the blocks without dragging the signal line:

    1. Vertically line up the output port and input port you want to connect with no other components between them. If the ports are already lined up, move one of the blocks to break the alignment, then line them up again. When you release the block that you moved to align the ports, a preview of the connection appears.

      A Sine Wave block is to the left of a Gain block. They are not connected. The Sine Wave block output port is horizontally aligned with the Gain block input port. A faint blue horizontal arrow points from the output port to the input port.

    2. To make the connection, click the preview.

      The Sine Wave block output port connects to the Gain block input port with a solid black signal line.

  • To connect the blocks without dragging the signal line or lining up the ports:

    1. Click the port symbol of the output port you want to connect. The port hint symbol Port hint symbol appears on the input ports of other components that you can connect to.

      A Gain block is below and to the right of a Sine Wave block. The port symbol of the Sine Wave block output port is highlighted in blue, and there is a port hint symbol in front of the Gain block input port.

    2. To see a preview of the connection, pause on the port hint symbol of the input port that you want to connect to.

      A light blue line connects the Sine Wave block output port to the Gain block input port.

    3. To make the connection, click the preview.

      A solid black line connects the Sine Wave output port to the Gain block input port.

  • To connect multiple blocks to a single block without dragging the signal line or lining up the ports:

    1. Left-click and drag a selection box around the blocks whose output ports you want to connect.

    2. Press Ctrl and right-click the block whose input ports you want to connect.

    The video shows three Outport blocks simultaneously connecting to the same Subsystem block.

  • To connect both the input port and output port of a block to an existing signal line, click and drag the block onto the signal line. Position the block such that the port symbols Port Symbol are on the signal line. When the output port symbol disappears and the input port symbol turns into a solid arrowhead, release your pointer.

    The top image shows a pointer holding a Gain block over a signal line, with the port symbols a little above the signal line. The bottom image shows the Gain block over the signal line such that the ports are right on top of the signal line. The right port symbol is not visible, and the left port symbol is changed to a solid arrowhead.

To make a signal line segment diagonal, press Shift and drag a vertex that connects to another signal line segment.

A Sine Wave block connects to a Scope block. The Sine Wave block is higher on the canvas than the Scope block. The signal line between the blocks consists of three line segments joined at two vertices. The pointer is dragging the lower vertex to the right. The line segment connecting to the Sine Wave block and the line segment connecting to the Scope block are horizontal. The line segment joining the two horizontal segments is diagonal.

Connect Single Output Port to Multiple Input Ports

To connect an output port to multiple input ports, connect one input port to the output port, then branch the signal line to connect to the other input ports.

To branch the signal line, press Ctrl, then click and drag the existing signal line to the input port of the block to which you want to connect.

A Sine Wave Block connected to a Gain block by a signal line, and a dotted line branching out of the signal line and reaching part of the way towards an unconnected second Gain block

Tip

To branch the line, you can also click and drag the port symbol of the unconnected input port onto the existing signal line.

The top image shows a Sine Wave block connected to a Gain block by a signal line, and an unconnected second Gain block with a dotted line part of the way towards the signal line. Above the dotted line is the text "Drag to Existing Signal Line". The bottom image shows the Sine Wave block connected to both Gain blocks.

Connect Output Ports of Multiple Blocks to Single Block

Some blocks can connect multiple signal lines on their input port side. For example, to plot multiple signals on one graph, you can connect the output ports of multiple blocks to a single Scope block.

To connect the output ports of multiple blocks to a single block, from each output port you want to connect, drag a signal line over the input port side (left edge) of the single block. When the block icon turns blue and the port number appears, release your pointer. An input port is created automatically to connect the signal line.

Two Constant blocks are to the left of a Scope block. The Scope block only has one port, and one of the Constant blocks connects to it. A blue signal preview line runs from the other Constant block to the left side of the Scope block. The Scope block icon is blue, and the port number 2 is displayed next to the point where the preview line connects to the Scope block.

If the blocks whose output ports you want to connect are not in the model yet, to increase the number of input ports on the single block:

  1. Pause on the input port side (the left edge) of the block until a plus sign appears next to the pointer.

    Pointer at left edge of Scope block, with boxed plus symbol near pointer

  2. Then, click and drag your pointer away from the block. A dashed signal line appears that you can connect to the output port of another block.

    Scope block with two input ports, with the top input port connected to signal line, and bottom input port unconnected

To delete an input port, click its port symbol and press Delete.

To specify the number of input ports a block has, use the Block Parameters dialog box or the Parameters tab of the Property Inspector.

Scope block Property Inspector dialog box with the Parameters tab showing and the "Number of input ports" parameter text box highlighted

Tip

For some blocks, you can enter the number of input ports when you add the block to the model.

The left image shows a Scope block with a prompt below it asking for the "Number of input ports" and the answer "2". The right image shows the resulting Scope block with two input ports.

Connect Subsystems

To send signals into a subsystem, the subsystem must contain as many input ports as signals that you want to send into the subsystem.

To receive signals from a subsystem, the subsystem must contain as many output ports as signals that you want to receive from the subsystem.

When you add a blank subsystem to the model, the subsystem contains an input port and an output port by default.

To connect a subsystem:

  1. To enter the subsystem, double-click the Subsystem block.

    Two unconnected Constant blocks on the left, an unconnected Subsystem block in the center, and two unconnected Scope blocks on the right

  2. Inside the subsystem, add the required number of input ports and output ports.

    Inside the Subsystem block, there are two unconnected input ports on the left, two unconnected gain blocks in the center, and two unconnected output ports on the right. The two input ports display the numbers 1 and 2 on the block icons, and so do the two output ports.

  3. Inside the subsystem, connect the input ports and output ports to the subsystem.

    Inside of the Subsystem block, the input port with the number 1 on the block icon connects to a Gain block, which connects to the output port with the number 1 on the block icon. The input port with the number 2 on the block icon connects to the other Gain block, which connects to the output port with the number 2 on the block icon.

  4. To navigate up a level in the model hierarchy, in the Explorer Bar at the top of the Simulink® canvas, click the name of the level to the left of the name of the Subsystem block.

    Explorer Bar showing the hierarchy model->Subsystem, with the callout "Click" pointing to the model level

  5. Connect the signal lines of the signals that you want to send into the subsystem to the input ports of the Subsystem block.

    Each input port on the Subsystem block corresponds to an Inport block inside the subsystem. You can tell which input port on the Subsystem block corresponds to which Inport block inside the subsystem by the port number.

  6. Connect the signal lines of the signals that you want to receive from the subsystem to the output ports of the Subsystem block.

    Each output port on the Subsystem block corresponds to an Outport block inside the subsystem.

    The two input ports of the Subsystem block connect to two Constant blocks, and the two output ports connect to two Scope blocks. The input ports and output ports of the Subsystem block have the same numbers on the block icon as the input ports and output ports inside the subsystem.

Tip

To avoid manually connecting subsystems, build the contents of the subsystem in the level of the model hierarchy where you want to add the Subsystem block. Then, convert the contents into a subsystem:

  1. Select the subsystem components by clicking and dragging your pointer across the canvas to draw a rectangle that encompasses the components.

  2. Pause on the ellipsis that appears.

  3. In the action bar that expands, click Create Subsystem.

The conversion to a subsystem automatically adds and connects the subsystem input ports and output ports.

Connect Blocks Without Signal Lines

Related blocks connect to each other without signal lines.

For example, the Goto and From blocks are related blocks that you can use to send a signal without a signal line. The signal that enters the Goto block exits the From block without passing through a signal line.

A Constant block connects to a Goto block with a signal line, and a From block connects to a Display block with a signal line. The Constant block has a value of 5.25, and the Display block shows a value of 5.25. The Goto block is selected, and the From block is highlighted in purple.

To connect related blocks, use the Block Parameters dialog box or the Parameters tab of the Property Inspector.

Tip

To check whether two or more related blocks are connected, select one. All related blocks that connect to the selected block highlight in purple.

Some related blocks connect using tags. For example, all Goto and From blocks with the same tag are connected.

Two rows of blocks are one above another. The top row contains a Constant block connected to a Goto block with a signal line, and a From block connected to a Display block with a signal line. The bottom row contains the same blocks. The value of the Constant block in the top row is 5.25. The tag on the Goto block icon in the top row is A, and the tag on the From block icon in the bottom row is A. The display block in the bottom row shows a value of 5.25. The value of the Constant block in the bottom row is-1. The tag on the Goto block icon in the bottom row is B, and the tag on the From block icon in the top row is B. The display block in the top row shows a value of -1.

You can set the tag for these blocks in the Block Parameters dialog box or in the Property Inspector, on the Parameters tab.

In the Goto block Block Parameters dialog box, the "Goto tag" parameter text box is highlighted and displays the value A.

Blocks from the Dashboard and Customizable Blocks libraries are also related blocks. You can connect display blocks from these libraries to signals. You can connect control blocks to block parameters or variables. For information about how to connect dashboard blocks, see Connect Dashboard Blocks to Simulink Model.

Convert Signal Lines to Goto and From Block Sets

You can simplify your model diagrams by replacing lengthy signal lines with Goto and From blocks. However, when you want to trace a signal path, seeing the signal lines can be useful.

You can convert signal lines and virtual buses to Goto and From block sets, and you can convert Goto and From block sets to signal lines. A Goto and From block set is a connected group of Goto and From blocks that have the same tag.

To perform the conversion, the signal lines, buses, or Goto and From blocks you want to convert must meet these conditions:

  • The lines, buses, or blocks are fully connected.

  • The lines, buses, or blocks are all in the same location in the model hierarchy, meaning on the same level and inside the same component.

  • If you want to convert lines or buses to blocks, the lines or buses are not connected to any Goto or From blocks.

You can perform the conversion regardless of whether the block tags are visible.

To convert a Goto block and all From blocks to which it connects or a From block and the Goto block to which it connects to a signal line, select the block. Pause on the ellipsis that appears above the selected block. In the action menu that expands, select Convert to signal.

A Sine Wave block is connected to a Goto block, and a From block is connected to a Scope block. The pointer selects the Goto block, and uses the action menu to convert the Goto and From blocks to a signal line that connects the Sine Wave block to the Scope block.

To convert a signal line or bus to a Goto and From block set, select the signal line or bus. Pause on the ellipsis that appears. In the action menu that expands, select Convert to Goto and From blocks.

Tip

Alternatively, perform one of these actions.

  • Select the block, and in the Simulink Toolstrip, on the Goto or From tab, click Convert to Signal.

  • Select the signal line or bus, and in the toolstrip, on the Signal tab, click Convert to Goto/From.

To convert multiple Goto and From block sets to signal lines simultaneously, press Shift and select the Goto blocks of all the sets you want to convert. In the Simulink Toolstrip, on the Signal tab, click Convert to Signal.

If a Goto block has multiple From blocks with the same tag, to convert a subset of the From blocks to signal lines, press Shift and select the From blocks you want to convert. In the toolstrip, on the Signal tab, click Convert to Signal. The selected From blocks convert to signal lines connected to the signal line coming out of the corresponding Goto block. The Goto block does not convert to a signal line.

To convert multiple signal lines or buses to Goto and From block sets simultaneously, press Shift and select the signal lines or buses. In the toolstrip, on the Signal tab, click Convert to Goto/From.

The pointer selects a signal line and uses the action menu to convert the signal line into a Goto and From block pair. The pointer then selects two signal lines and uses the toolstrip to convert the signal lines to a Goto and From block set.

Comment Out and Comment Through Blocks

You can exclude blocks from simulation without physically removing the blocks from the model by commenting out or commenting through the blocks.

  • Comment Out: Excludes the selected block from simulation. The signals are terminated and grounded.

  • Comment Through: Excludes the selected block from simulation. The signals are passed through. To comment through, a block must have the same number of input and output ports and no control or connection ports.

Note

These Simulink blocks do not support the Comment Out and Comment Through commands:

  • Inport

  • Outport

  • Connection ports

  • Argument Inport

  • Argument Outport

  • Data Store Memory

  • Goto Tag Visibility

The Signal Generator block does not support the Comment Through command.

To comment out a block, select the block. In the action bar that appears, click Comment Out.

Selected Constant block with the action bar above it, and the Comment Out button selected with the tooltip "Comment Out" displayed above it

To comment through a block, right-click the block and select Comment Through.

Tip

Alternatively, select the block and press:

  • Ctrl+Shift+X to comment out

  • Ctrl+Shift+Y to comment through

Related Topics