User`s guide

3 Writing S-Functions As C-MEX files
3-62
matlabroot/simulink/src/dsfunc.c
/* File : dsfunc.c
* Abstract:
*
* Example C MEX S-function for defining a discrete system.
*
* x(n+1) = Ax(n) + Bu(n)
* y(n) = Cx(n) + Du(n)
*
* For more details about S-functions, see simulink/src/sfuntmpl.doc.
*
* Copyright (c) 1990-1998 by The MathWorks, Inc. All Rights Reserved.
* $Revision: 1.3 $
*/
#define S_FUNCTION_NAME dsfunc
#define S_FUNCTION_LEVEL 2
#include "simstruc.h"
#define U(element) (*uPtrs[element]) /* Pointer to Input Port0 */
static real_T A[2][2]={ { -1.3839, -0.5097 } ,
{ 1 , 0 }
};
static real_T B[2][2]={ { -2.5559, 0 } ,
{ 0 , 4.2382 }
};
static real_T C[2][2]={ { 0 , 2.0761 } ,
{ 0 , 7.7891 }
};
static real_T D[2][2]={ { -0.8141, -2.9334 } ,
{ 1.2426, 0 }
};
/*====================*
* S-function routines *
*====================*/
/* Function: mdlInitializeSizes ===============================================
* Abstract:
* The sizes information is used by Simulink to determine the S-Function
* block's characteristics (number of inputs, outputs, states, etc.).
*/
static void mdlInitializeSizes(SimStruct *S)
{
ssSetNumSFcnParams(S, 0); /* Number of expected parameters */
if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {