Skip to Main Content Skip to Search
Product Documentation

Types of Custom Blocks

MATLAB Function Blocks

A MATLAB Function block allows you to use the MATLAB language to define custom functionality. These blocks are a good starting point for creating a custom block if:

You can create a custom block from a MATLAB 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 MATLAB Function blocks while you cannot generate code for models containing an 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 required behavior, you can convert it into a custom block by:

  1. Masking the block to hide the block 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.

For more information, see Working with Block Libraries and Working with Block Masks.

S-Function Blocks

S-function blocks allow you to write MATLAB, 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 Simulink Coder 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 Generated S-Function Block in the Simulink Coder User's Guide for details and limitations on using the S-function target.

Comparing MATLAB S-Functions to MATLAB Functions for Code Generation

MATLAB S-functions and MATLAB functions for code generation 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 Simulink Coder User's Guide for more information.

See Example Using S-Functions to Incorporate Legacy C Code in the Simulink Developing 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-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS