Writing S-Functions | ![]() ![]() |
Building S-Functions Automatically
The S-Function Builder is a Simulink block that builds an S-function from specifications and C code that you supply. The S-Function Builder also serves as a wrapper for the generated S-function in models that use the S-function. This section explains how to use the S-Function Builder to build simple C MEX S-functions.
To build an S-function with the S-Function Builder:
mex
command to work on your system.
mex
command, type mex -setup
at the MATLAB command
line.
Deploying the Generated S-Function
To use the generated S-function in another model, first check to ensure that the directory containing the generated S-function is on the MATLAB path. Then copy the S-Function Builder block from the model used to create the S-function into the target model and set its parameters, if necessary, to the values required by the target model.
How the S-Function Builder Builds an S-Function
The S-Function Builder builds an S-function as follows. First, it generates the following source files in the current directory:
sfun.c
sfun
is the name of the S-function that you specified in the S-function name field of the S-Function Builder's dialog box. This file contains the C source code representation of the standard portions of the generated S-function.
sfun_wrapper.c
sfun.tlc
After generating the S-function source code, the S-Function Builder uses the MATLAB mex
command to build the MEX file representation of the S-function from the generated source code and any external custom source code and libraries that you specified.
![]() | Writing S-Functions in C | S-Function Builder Dialog Box | ![]() |