| Products & Services | Industries | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Simulink |
| Contents | Index |
| Learn more about Simulink |
No
#define MDL_DERIVATIVES
void mdlDerivatives(SimStruct *S)
Derivatives(s)
Instance of Simulink.MSFcnRunTimeBlock class representing the Level-2 M-File S-Function block
The Simulink engine invokes this optional method at each time step to compute the derivatives of the S-function's continuous states. This method should store the derivatives in the S-function's state derivatives vector. In a C MEX S-function, use ssGetdX to get a pointer to the derivatives vector. In a Level-2 M-file S-function, use the run-time object's Derivatives method.
Each time the mdlDerivatives routine is called, it must explicitly set the values of all derivatives. The derivative vector does not maintain the values from the last call to this routine. The memory allocated to the derivative vector changes during execution.
Note When generating code for a noninlined C MEX S-function that contains this method, make sure the method is not wrapped in a #if defined(MATLAB_MEX_FILE) statement. For example: #define MDL_DERIVATIVES
#if defined(MDL_DERIVATIVES) && defined(MATLAB_MEX_FILE)
static void mdlDerivatives(SimStruct *S)
{
/* Add mdlDerivatives code here *
}
#endif The define statement makes the mdlDerivatives method available only to a MATLAB MEX-file. If the S-function is not inlined, the Real-Time Workshop product cannot use this method, resulting in link or run-time errors. |
For a C MEX S-function example, see matlabroot/toolbox/simulink/simdemos/simfeatures/src/csfunc.c.
For a Level-2 M-file S-function example, see matlabroot/toolbox/simulink/simdemos/simfeatures/ msfcn_limintm.m.
C, C++, M
![]() | mdlCheckParameters | mdlDisable | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |