The following table gives an overview of how to write different types of Sfunctions. See the associated sections of the Sfunction documentation for more details on how to implement Sfunctions using a particular method.
Note For backward compatibility, the following table and sections contain information about Level1 MATLAB^{®} Sfunctions. However, use the Level2 MATLAB Sfunction API to develop new MATLAB Sfunctions. 
SFunction Type  Implementation 

Level1 MATLAB Sfunction  Use the following template to write a new Level1 MATLAB Sfunction: sfuntmpl.m See Maintain Level1 MATLAB SFunctions for more information. 
Level2 MATLAB Sfunction 

Handwritten C MEX Sfunction 

SFunction Builder 

Legacy Code Tool  Use the legacy_code function to perform
the following steps (see Integrate C Functions Using Legacy Code Tool):
