S-Function Examples - MATLAB & Simulink (original) (raw)
These examples show you how to work with a variety of S-functions or programs that use S-functions, including C/C++ S-functions, Fortran S-functions, S-function Builder, Level 2 MATLABĀ® S-functions, and Blockset Designer. Each section explains how to open the files and what is in them. These are good places to continue to develop an understanding of S-functions after learning the basics. These do not represent all the examples available for S-functions, but a relevant subsection.
Access S-Function Examples
Most of the S-function examples are run through [sfundemos](https://mdsite.deno.dev/matlab:open%5Fsystem%28'sfundemos'%29;)
. This example library contains S-function models and is grouped by coding type, such as C S-functions or C++ S-functions.
To run an example from [sfundemos](https://mdsite.deno.dev/matlab:open%5Fsystem%28'sfundemos'%29;)
:
- In the MATLAB Command Window, enter
[sfundemos](https://mdsite.deno.dev/matlab:open%5Fsystem%28'sfundemos'%29;)
.
The S-function example library opens.
Each block represents a category of S-function examples. - Double-click a category to display the examples that it includes. For example, click C-files.
- Double-click a block to open and run the example that it represents.
It might be helpful to examine some sample S-functions as you read the next chapters. Code for the examples is stored in the following folder under the MATLAB root folder.
MATLAB code | toolbox/simulink/sfuntemplates |
---|---|
C, C++, and Fortran code | toolbox/simulink/sfuntemplates/src |
Level-2 MATLAB S-Function Examples
The_`matlabroot`_/toolbox/simulink/sfuntemplates
folder (open) contains many Level-2 MATLAB S-functions. Consider starting off by looking at these files. For more on Level-2 MATLAB S-functions, see Write Level-2 MATLAB S-Functions.
C S-Function Examples
The_`matlabroot`_/toolbox/simulink/sfuntemplates/src
folder (open) contains examples of C MEX S-functions, many of which have a MATLAB S-function counterpart. The C MEX S-functions are listed in the following table. For more on C S-functions, see C/C++ S-Function Basics andBuild S-Functions Automatically Using S-Function Builder.
Fortran S-Function Examples
The following table lists sample FortranĀ® S-functions available in the_`matlabroot`_/toolbox/simulink/sfuntemplates/src
folder (open). For more on Fortran S-functions, see Create Level-2 Fortran S-Functions.
C++ S-Function Examples
The following table lists sample C++ S-functions available in the_`matlabroot`_/toolbox/simulink/sfuntemplates/src
folder (open). For more on C++ S-functions, see C/C++ S-Function Basics andBuild S-Functions Automatically Using S-Function Builder.
Organizing S-Function in a Project
The following example shows how to arrange S-function artifacts into a project. This is accomplished using the Blockset Designer feature. For more on Blockset Designer, see Create a Blockset Project.
See Also
Level-2 MATLAB S-Function | S-Function Builder | S-Function | MATLAB Function