Main Content

mdlSetOperatingPoint

Restore operating point of C MEX S-function

Required

No

Languages

C, C++

Syntax

#define MDL_OPERATING_POINT
void mdlSetOperatingPoint(SimStruct* S, const mxArray* in)

Arguments

S

SimStruct that represents an S-Function block.

const mxArray* in

Operating point of S-function created by the mdlGetOperatingPoint method.

Description

The Simulink® engine invokes this custom method to restore the S-function operating point when restoring the operating point for the model that uses the S-function. The software restores the model operating point when you explicitly configure a model to load an initial state that you specify as a Simulink.op.ModelOperatingPoint object and when you use features that rely on the model operating point internally, such as fast restart.

You must implement this method when you specify custom operating point compliance (USE_CUSTOM_OPERATING_POINT) using ssSetOperatingPointCompliance.

Examples

/* Function: mdlSetOperatingPoint
 * Abstract:
 *   Unpack the MATLAB structure passed and restore it to
 *   the RunTimeData structure
 */
static void mdlSetOperatingPoint(SimStruct* S, 
    const mxArray* simSnap)
    {
    RunTimeData_T* rtd = 
	  (RunTimeData_T*)ssGetPWorkValue(S, 0);

    /* Check and load the count value */
    {
        const mxArray* cnt = 
				mxGetField(simSnap, 0, fieldNames[0]);
        ERROR_IF_NULL(S,cnt,
				"Count field not found in simulation state");
        if ( mxIsComplex(cnt) ||
             !mxIsUint64(cnt) ||
             mxGetNumberOfElements(cnt) != 1 ) {
            ssSetErrorStatus(S, "Count field is invalid");
            return;
        }
        rtd->cnt = ((uint64_T*)(mxGetData(cnt)))[0];
    }
}

Version History

Introduced in R2019a

expand all