mdlDerivatives
Compute the C MEX S-function's derivatives
Required
No
并出口ages
C, C++
Syntax
#define MDL_DERIVATIVESvoid mdlDerivatives(SimStruct *S)
Arguments
-
S
-
SimStruct representing an S-Function block.
Description
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, usessGetdX
to get a pointer to the derivatives vector.
Each time themdlDerivatives
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
If you haveSimulink Coder™, 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
define
statement makes themdlDerivatives
method available only to a MATLAB®MEX file. If the S-function is not inlined, theSimulink Coderproduct cannot use this method, resulting in link or run-time errors.
Example
For a C MEX S-function example, seecsfunc.c
.