mdlGetSimState

(Not recommended) Return the C MEX S-function simulation state as a valid MATLAB data structure, such as a matrix structure or a cell array.

Note

mdlGetSimState is not recommended. Use mdlGetOpeartingPoint instead.

Required

No

Languages

C, C++

Syntax

#define MDL_SIM_STATE
mxArray* mdlGetSimState(SimStruct* S)

Arguments

S

SimStruct representing an S-Function block.

Description

The Simulink® engine invokes this custom method to get the simulation state (SimState) of the model containing S. A call to this method should occur after mdlStart and before mdlTerminate to ensure that all of the S-function data structures (e.g., states, DWork vectors, and outputs) are available.

Example

/* Function: mdlGetSimState
 * Abstract:
 * Package the RunTimeData structure as a MATLAB structure
 * and return it.
 */
static mxArray* mdlGetSimState(SimStruct* S)
{
		RunTimeData_T* rtd =
			(RunTimeData_T*)ssGetPWorkValue(S, 0);
		const char* fieldNames[] = {"Count"};

		/* Create a MATLAB structure to hold the run-time data */
		mxArray* simSnap =
		mxCreateStructMatrix(1, 1, 1, fieldNames);
		mxSetField(simSnap, 0, fieldNames[0],
			mxCreateDoubleScalar(rtd->cnt));
		return simSnap;
}
Introduced in R2009a