This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

mdlSetSimState

(Not recommended) Set the simulation state of the C MEX S-function by restoring the SimState.

Note

mdlSetSimState is not recommended. Use mdlSetOperatingPoint instead.

Required

No

Languages

C, C++

Syntax

#define MDL_SIM_STATE
void mdlSetSimState(SimStruct* S, const mxArray* in)

Arguments

S

SimStruct representing an S-Function block.

const mxArray* in

Any valid MATLAB data.

Description

The Simulink® engine invokes this custom method at the beginning of a simulation of the model containing S . Simulink sets the initial simulation state of the S-function to the SimState of the model.

Example

/* Function: mdlSetSimState 
 * Abstract:
 *   Unpack the MATLAB structure passed and restore it to
 *   the RunTimeData structure
 */
static void mdlSetSimState(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];
    }
}

Introduced in R2009a