Skip to content
Tutorials Center
My learning

Topics

Lesson 13 of 36 ยท Signals and Subsystems

Simulink Masks, Block Libraries and Model Reference

Package reusable Simulink components: create masks with parameters and icons, build and link block libraries, and split large designs into referenced models with the Model block.

When the same piece of logic appears ten times with different numbers, copying and pasting subsystems is a trap: a bug fix must then be made ten times. Simulink has three tools for reuse. A mask gives a subsystem its own dialog and icon. A library keeps one master copy that many linked blocks follow. Model referencing splits a large design into separate model files that can be built, tested and compiled independently.

Simulink does not run on this site. The product steps below describe the real tools; the Python stand-ins show the logic behind masking and linking.

Masks: a friendly face for a subsystem

A mask hides the inside of a subsystem and replaces its many inner parameters by a small dialog you design. To create one:

  1. Select the subsystem and press Ctrl+M (or right-click > Mask > Create Mask).
  2. In the Mask Editor use these tabs:
Tab What you define
Icon & Ports Drawing commands for the block face such as disp('LPF'), plot(x, y), image(...) or port_label('input', 1, 'u')
Parameters & Dialog Prompts and mask parameters (Edit, Check box, Popup, Slider, Table...). Each has a name used by the blocks inside
Initialization MATLAB code run when the model loads or a parameter changes, in the mask workspace. Compute derived values here, e.g. Ts = 1/fs;
Documentation Type, description and help text shown in the dialog

Inside the subsystem you use the mask parameter names exactly like workspace variables: a Gain block with value Kp, a Transfer Fcn with denominator [tau 1].

Initialization code can also validate. Use error('Cutoff must be below Nyquist') or use the Constraint feature of a parameter so an invalid dialog value is rejected.

A mask in four parts

Icon What the block looks like
Parameters Dialog fields
Initialization Derived values, checks
Documentation Help for users

Masks turn a subsystem into a product.

1 / 2

You can read and set mask values from MATLAB. get_param(gcb, 'MaskValues') returns the values as strings, and set_param(gcb, 'Kp', '12') changes the mask parameter named Kp.

Block libraries

A library is a special model whose blocks are masters. To make one: New > Library on the Start Page, or new_system('mylib', 'Library'). Put masked subsystems into it and save. To use the library:

  • Open the Library Browser, find your library (the folder must be on the MATLAB path), and drag blocks in, or
  • Drag a block from the open library window.

The copy in your model is a library link (a small arrow in a corner; a library block shows its link status with a badge). Editing the master and saving the library updates every linked block when models are updated (Ctrl+D). Rules to remember:

  • You cannot edit the inside of a linked block unless you Disable link (right-click > Library Link > Disable Link), and then it is a plain copy again.
  • Use Library Link > Restore Link to reconnect, or Library Link > Go To Library Block to open the master.
  • Library blocks should be parameterized (masked), not hard-coded, so that each instance can have its own values.
  • Keep libraries in your Simulink Project and on the path so linked blocks resolve on every machine.

Model referencing

For larger projects, split the design into models and combine them with Model blocks (Ports & Subsystems > Model). Compared to a subsystem, a referenced model:

  • is its own file, reusable by several parents and testable alone;
  • compiles into its own simulation target, so only changed models rebuild;
  • can be protected or developed by a different team;
  • uses ports and buses for all data exchange (no Goto/From across the boundary);
  • can have its own data dictionary and solver rules, but follows the top model's solver and settings;
  • supports Normal and Accelerator simulation modes (Accelerator generates and runs compiled code for the referenced model and is much faster for large models; Normal mode allows debugging).

You can create a referenced model from a subsystem: right-click > Subsystem & Model Reference > Convert to > Referenced Model.

Model arguments let each instance take a different parameter value: declare the variable in the referenced model workspace as an argument and pass the value in the Model block's Instance parameters.

Need Choose
Group blocks for readability Subsystem
Repeated block with different parameters and one master Masked subsystem in a library
Separate file, independent build, many people Referenced model
Replace one design with alternatives Variant subsystem or variant model reference

Stand-ins

Python Stand-in: a masked block with parameters and validation (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.

Python Stand-in: library links follow the master (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.

Checklist before reusing

  • Does the component have a clear interface (names, types, units)?
  • Are its parameters masked with sensible defaults and validation?
  • Is it tested alone (see the testing chapter of this tutorial)?
  • Is there help text so someone else can use it?
  • Does the library live somewhere on the path of every user?

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which shortcut opens the Mask Editor for a selected subsystem?

    Ctrl+M creates or edits a mask.
  2. 2. What happens to linked blocks when the library master is edited and saved?

    Linked blocks follow the master unless the link is disabled.
  3. 3. Where do masked-block initialization commands run?

    Mask initialization code runs in the mask's own workspace.
  4. 4. Which is NOT true about referenced models?

    Signals cross a model reference boundary only through ports and buses.

Summary

  • A mask gives a subsystem its own icon, parameter dialog, initialization code and help.
  • Libraries hold master blocks; linked blocks update with the master unless you disable the link.
  • Referenced models are separate files with ports, separate builds and Accelerator mode.
  • Choose subsystem, library block or referenced model by how much independence and reuse you need.

Next: Integrators and Differential Equations