This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

S-Function Types

Consider the following questions if you are unclear about what type of S-function is best for your application.

If you...Then use...
Are a MATLAB® programmer with little or no C programming experienceA Level-2 MATLAB S-function, especially if you do not need to generate code for a model containing the S-function (see Write Level-2 MATLAB S-Functions).
Need to generate code for a model containing the S-functionEither a Level-2 MATLAB S-function or a C MEX S-functions. Level-2 MATLAB S-functions require that you write a Target Language Compiler (TLC) file for your S-function, before generating code. C MEX S-functions, however, automatically support code generation.
Need the simulation to run fasterA C MEX S-function, even if you do not need to generate code (see Creating C MEX S-Functions). For complicated systems, Level-2 MATLAB S-functions simulate slower than C MEX S-functions because they call out to the MATLAB execution engine.
Need to implement the S-function in C, but have no previous experience writing C MEX S-functionsThe S-Function Builder.
Are incorporating legacy code into the modelAny S-function, with the exception of a Level-1 MATLAB S-function. Consider using the Legacy Code Tool if your legacy function calculates only outputs, not dynamic states (see Integrate C Functions Using Legacy Code Tool). Otherwise, consider using the S-Function Builder. If you need to call the legacy code during simulation, do not use a Level-2 MATLAB S-function because they call legacy code only through their TLC files.
Need to generate embeddable code for an S-function that incorporates legacy codeThe Legacy Code Tool if your legacy function calculates only outputs. Otherwise, use a handwritten C MEX S-function or the S-Function Builder.

Was this topic helpful?