In this article you will learn :

  • How to create a Simulink library
  • How to link a block to a library

Create a Simulink Library

Let’s start with the following model:

Simple Model to Run

We’ll create a library block that will add 1 to its input. We can create that block with the following:

Then, select the constant block and the sum block to create a subsystem (using CTRL+G or right click > Create Subsystem from Selection).  You can create the library where you want to put your block:

Click on the arrow to select “Library…” on the Drop-down Menu:

Finally select “Blank Library”:

As a side note, if you have an older version than MATLAB R2016b, you may not have this window, but you should not have difficulty finding the blank library. This will create a blank library that you need to save in order to link the Subsystem block to it:

Congratulations, you successfully created a library.

How to Link a Block to a Library

Once the library has been created, linking a block to a library is really easy. You just have to do the following:

  1. Select the desired block (namely “Subsystem”) 
  2. Cut it using CTRL+X
  3. Paste it into the desired library (namely “myPersonalLibrary”): CTRL+V
  4. Copy the same block from the library: CTRL+C
  5. Paste it in your model: CTRL+V

Then, You can go inside the Subsytem block in your model and try moving one of the blocks. You should see the following: 

This indicates that you successfully linked this block to the library “myPersonalLibrary.slx.”