Types of Custom Blocks - MATLAB & Simulink (original) (raw)

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, whereas you cannot generate code for models containing a Fcn block.

MATLAB System Blocks

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

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 box.
  2. Placing the block in a library to prohibit modifications and allow for easily updating copies of the block.

For more information, see Custom Libraries and Author Block Masks.

C Caller Block

The C Caller block allows you to integrate C code into Simulink blocks. These blocks serve as a good starting point for creating a custom block if:

C Function Block

The C Function block allows you to integrate C code into Simulink blocks. These blocks serve as a good starting point for creating a custom block if:

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 Use S-Function Target for Model or Subsystem (Simulink Coder) in the Simulink Coder User's Guide for details and limitations on using the S-function target.

Masked Blocks

You can customize any block by adding a mask to it. A mask is a custom interface to the block. You can customize a block using a mask in many ways, such as:

To learn more about masked blocks, see Author Block Masks.

See Also

Fcn | Interpreted MATLAB Function | C Caller | C Function | Level-2 MATLAB S-Function | MATLAB Function | MATLAB System | S-Function | S-Function Builder | Simulink Function | Subsystem