Real Technology Tools

Vector in Simulink: Define, Concatenate, and Use a Scope

In this article, you’ll learn how to use the Mux block to create Simulink vectors as well as how to use the other Simulink blocks needed to manipulate them. More specifically, you’ll learn to:

Simulink Mux: Create a Vector in Simulink

In order to create Simulink vectors, you have to create at least two signals from which you can create a Simulink vector. Let’s try creating a Simulink model that we will name “vectorExample.slx.” To do that, follow these steps:

Observe a Vector in the Simulink Scope

In order to do this, simply add a scope to your model and connect it to the mux block:

Then, run your model and double-click on the scope, you should have the following:

As you can see both signals are on the same scope but with different colors.

This is the easiest way to observe a vector. However, you can also split the vector to observe every element separately in a scope, as we will see in the next section.

Demux Simulink Block: Splitting a Vector

If you want to split the vector that you created into every single element, you can use the Demux block:

Let’s say you only want to visualize the second signal element from your vector: how do you select this signal specifically and visualize it without having to use a Demux block and output every single element of your vector? (In our example, it is fine to output every element because we only have 2, but keep in mind that in a real-life example you could have lots of signals in a vector, and it would take a significant amount of time if you use a Demux block.)

The answer is to use a selector block.

Using A Selector Block in Simulink

Let’s use a selector block to visualize the second element of our Simulink vector only.

If you connect this selector to a scope and run the simulation, you get the following :

This is the second element of our input vector, which is what we wanted to observe.

Key takeaways:

  1. You can create a vector by using the Mux Simulink block:
    • The Mux block is located in the Simulink library “Simulink/Signal Routing.”
    • Add an input signal to the Mux block by double-clicking on it and using the “Number of inputs” box.
  2. Connect a vector to a scope and observe it using the following color code:
    • yellow
    • magenta
    • cyan
    • red
    • green
    • dark blue

    The first signal is in yellow, the second is in magenta, etc.

  3. You can output every element of a vector using a Demux block:
    • The Demux block is located in the Simulink library “Simulink/Signal Routing.
    • Add an output signal to the Demux block by double-clicking on it and using the “Number of outputs” box.
  4. Find and extract a specific signal by using the selector block and setting the index to the element(s) that you want to output and the input port size to the size of your input vector.

If you want more information about mux signals, see the following MathWorks documentation: https://www.mathworks.com/help/simulink/ug/virtual-signals.html#brp5v4k-1

Exit mobile version