Start Your First Python Project in 3 Steps: Grab Your Free Online Course Right Now!

If you did not follow the first part of this tutorial, here is the model we used:

Simulink Model Generated from Matlab

In this article, you will learn how to:

  • Define variables locally to a Subsystem
  • Add parameters to a mask

Defining Variables Locally to a Subsystem

You may want to make sure that the variables you define for a subsystem are not conflicting with other variables of the same name. This can be done after creating a mask (see the first part of this tutorial) and following these steps:

  1. Right click the subsystem > Mask > Edit Mask…
  2. Go to the “Initialization” tab
  3. Define a variable (e.g. “increment”)
  4. Go inside the subsystem (click the block > CTRL+u) and change the constant block value to the name of your variable

If you run the model, you will see that the Sine Wave has been incremented by 2:

To make sure that the variable “increment” has been defined locally to your subsystem, you can define it again in your workspace environment with a different value. Then, check that after running the model you still have your sine wave incremented by the same value.

Add Parameters to a Mask

In addition to defining the variable locally, you may want to define it as a parameter of your subsystem mask. To do so, you need to follow these steps:

  1. Right click the subsystem > Mask > Edit Mask…
  2. Remove the definition of the variable “increment” from the “Initialization” tab
  3. Go to the “Parameters & Dialog” tab
  4. Drag and drop the “Edit” parameter in the “Controls” panel
  5. Write the name of your variable in the “Name” section of the “Dialog box” panel (i.e. “increment”)
  6. You can also write something in the “Prompt” section of the “Dialog box” panel (e.g. “increment value:”). This is what will be prompted when you double click on your subsystem. (Note: this is optional.)
  7. Click “Apply” and close the window

Double click on the subsystem and try to put a value in the mask.

Run the model and make sure that the value in the field “increment value:” reflects how your sine wave output is incremented.

Leave a Reply