Products & Services Solutions Academia Support User Community Company

Learn more about Simulink   

Types of Custom Blocks

MATLAB Function Blocks

MATLAB function blocks allow you to use functions to define custom functionality. These blocks serve as a good starting point for creating a custom block if:

You can create a custom block from an M-function using one of the following types of MATLAB function blocks.

Each of these blocks has advantages in particular modeling applications. For example, you can generate code from models containing Embedded MATLAB Function blocks while you cannot generate code for models containing a Fcn block.

Subsystem Blocks

Subsystem blocks allow you to build a Simulink diagram to define custom functionality. These blocks serve as a good starting point for creating a custom block if:

Once you have a Simulink subsystem that models the desired behavior, you can convert it into a custom block by:

  1. Masking the block to hide the block's contents and provide a custom block dialog.

  2. Placing the block in a library to prohibit modifications and allow for easily updating copies of the block.

See Working with Block Libraries and Working with Block Masks in Using Simulink for more information.

S-Function Blocks

S-function blocks allow you to write M, C, or C++ code to define custom functionality. These blocks serve as a good starting point for creating a custom block if:

You can create a custom block from an S-function using one of the following types of S-function blocks.

The S-function target in the Real-Time Workshop product automatically generates a C MEX S-function from a graphical subsystem. If you want to build your custom block in a Simulink subsystem, but implement the final version of the block in an S-function, you can use the S-function target to convert the subsystem to an S-function. See Creating Component Object Libraries and Enhancing Simulation Performance in the Real-Time Workshop User's Guide for details and limitations on using the S-function target.

Comparing M-File S-Functions to Embedded MATLAB Functions

M-file S-functions and Embedded MATLAB functions have some fundamental differences.

Using S-Function Blocks to Incorporate Legacy Code

Each S-function block allows you to incorporate legacy code into your model, as follows.

See Integration Options in the Real-Time Workshop User's Guide for more information.

See Example Using S-Functions to Incorporate Legacy C Code in "Writing S-Functions" for an example.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS