Documentation Center

  • Trial Software
  • Product Updates

Contents

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)
{
    int n = ssGetInputPortWidth(S, 0);
    RunTimeData_T* rtd = 
		(RunTimeData_T*)ssGetPWorkValue(S, 0);

    /* Create a MATLAB structure to hold the run-time data */
    mxArray* simSnap = 
		mxCreateStructMatrix(1, 1, nFields, fieldNames);
return simSnap;
}
Was this topic helpful?