This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

C/C++ S-Function Basics

Learn the basics of S-functions

An S-function is a computer language description of a Simulink® block written in MATLAB®, C, C++, or Fortran. C, C++, and Fortran S-functions are compiled as MEX files using the mex utility. See Build MEX File (MATLAB). As with other MEX files, S-functions are dynamically linked subroutines that the MATLAB execution engine can automatically load and execute.

You can implement your S-functions using one of these ways:

  • Level-2 MATLAB S-function — Provides access to a more extensive set of the S-function API and supports code generation.

  • C MEX S-function — Enables you to implement your algorithm as a C MEX S-function or write a wrapper S-function to call existing C, C++, or Fortran code.

  • The S-Function Builder — Provides a graphical user interface that is used to generate new S-functions or incorporate existing C or C++ code without interacting with the S-function API.

  • The Legacy Code Tool — Provides a set of MATLAB commands that helps you create an S-function to incorporate legacy C or C++ code.


What Is an S-Function?

Learn how S-functions work.

S-Function Concepts

Learn key concepts needed to write different types of S-functions.

S-Function Callback Methods

Implement S-function callback methods.

S-Function Types

Use these guidelines to choose an S-function implementation for a particular application.

Implement S-Functions

Learn how to implement different types of S-functions.

S-Function Features and Limitations

Compare and contrast features supported by different types of S-function implementations.