Custom Block Examples

Creating Custom Blocks from Masked Library Blocks

The Additional Math and Discrete Simulink® library is a group of custom blocks created by extending the functionality of built-in Simulink blocks. The Additional DiscreteAdditional Discrete library contains a number of masked blocks that extend the functionality of the standard Unit Delay block. See Libraries for more general information on Simulink libraries.

Creating Custom Blocks from MATLAB Functions

The Simulink product provides a number of examples that show how to incorporate MATLAB® functions into a custom block.

  • The Single Hydraulic Cylinder Simulation, sldemo_hydcylsldemo_hydcyl, uses a Fcn block to model the control valve flow. In addition, the Control Valve Flow block Control Valve Flow block is a library link to one of a number of custom blocks in the library hydlibhydlib.

  • The Radar Tracking Model, sldemo_radarsldemo_radar, uses an Interpreted MATLAB Function block to model an extended Kalman filter. The MATLAB function aero_extkalman.maero_extkalman.m implements the Kalman filter found inside the Radar Kalman FilterRadar Kalman Filter subsystem. In this example, the MATLAB function requires three inputs, which are bundled together using a Mux block in the Simulink model.

  • The Spiral Galaxy Formation example, sldemo_eml_galaxysldemo_eml_galaxy, uses several MATLAB Function blocks to construct two galaxies and calculate the effects of gravity as these two galaxies nearly collide. The example also uses MATLAB Function blocks to plot the simulation results using a subset of MATLAB functions not supported for code generation. However, because these MATLAB Function blocks have no outputs, the Simulink Coder™ product optimizes them away during code generation.

Creating Custom Blocks from System Objects

The Simulink product provides a number of examples that show how to incorporate System objects into a custom block. Access the MATLAB source code for each System object™ by clicking the Source code link from the block dialog box. For more information on using MATLAB System blocks and System objects, see System Object Integration).

Creating Custom Blocks from S-Functions

The Simulink model sfundemossfundemos contains various examples of MATLAB and C MEX S-functions. For more information on writing MATLAB S-functions, see Write Level-2 MATLAB S-Functions. For more information on writing C MEX S-functions, see C/C++ S-Functions. For a list of available S-function examples, see S-Function Examples in Writing S-Functions.

Was this topic helpful?