Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

mdlGetSimState

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

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

Was this topic helpful?