Write Noninlined S-Function - MATLAB & Simulink (original) (raw)

Main Content

A noninlined S-function is a C or C++ MEX S-function that is treated identically by the Simulink® engine and by the generated code. You implement your algorithm once according to the S-function API. The Simulink engine and generated code call the S-function routines (for example,mdlOutputs) during model execution.

Noninlined S-functions are identified by the absence of an_`sfunction`_.tlc file for your S-function. The file name varies depending on your platform. For example, on a 64-bit Microsoft® Windows® system, the file name is_`sfunction`_._`mexw64`_. In the MATLAB® Command Window, type mexext to see which extension your system uses.

Guidelines for Writing Noninlined S-Functions

#ifdef MATLAB_MEX_FILE /* Is this file being compiled as a MEX-file? /
#include "simulink.c" /
MEX-file interface mechanism /
#else
#include "cg_sfun.h" /
Code generation registration function */
#endif

#ifdef MATLAB_MEX_FILE
#endif

Noninlined S-Function Parameter Type Limitations

Parameters to noninlined S-functions can be of the following types only:

For more flexibility in the type of parameters that you can supply to S-functions or the operations in the S-function, inline your S-function and consider using anmdlRTW S-function routine.

Use of other functions from the MATLABmatrix.h API or other MATLAB APIs, such as mex.h and mat.h, are not supported. If you call unsupported APIs from an S-function source file, compiler errors occur. For details on supported MATLAB API functions, see the files_`matlabroot`_/rtw/c/src/[rt_matrx.h](https://mdsite.deno.dev/matlab:edit%28fullfile%28matlabroot,'/rtw/c/src/rt%5Fmatrx.h'%29%29) and_`matlabroot`_/rtw/c/src/[rt_matrx.c](https://mdsite.deno.dev/matlab:edit%28fullfile%28matlabroot,'/rtw/c/src/rt%5Fmatrx.c'%29%29)

If you use mxGetPr on an empty matrix, the function does not return NULL. It returns a random value. Therefore, you must protect calls to mxGetPr by usingmxIsEmpty.

See Also

Topics