Skip to Main Content Skip to Search
Product Documentation

mdlSetSimState - Set the simulation state of the S-function by restoring the SimState.

Required

No

C Syntax

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

C Arguments

S

SimStruct representing an S-Function block.

const mxArray* in

Any valid MATLAB data.

MATLAB Syntax

SetSimState(s, in)

MATLAB Arguments

s

Instance of Simulink.MSFcnRunTimeBlock class representing the Level-2 MATLAB S-Function block.

in

The MATLAB data of type returned by GetSimState.

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.

C Example

/* Function: mdlSetSimState 
 * Abstract:
 *   Unpack the MATLAB structure passed and restore it to
 *   the RunTimeData structure
 */
static void mdlSetSimState(SimStruct* S, 
const mxArray* simSnap)
{
    unsigned n = (unsigned)(ssGetInputPortWidth(S, 0));
    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];
    }

Languages

C, C++, MATLAB

See Also

mdlInitializeConditions, mdlGetSimState

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS