MATLAB SIMULINK 7 - DEVELOPING S-FUNCTIONS Guida Utente Pagina 90

  • Scaricare
  • Aggiungi ai miei manuali
  • Stampa
  • Pagina
    / 210
  • Indice
  • SEGNALIBRI
  • Valutato. / 5. Basato su recensioni clienti
Vedere la pagina 89
3 Writing S-Functions As C-MEX files
3-46
the mdlZeroCrossings routine to return the nonsampled zero crossings. See
matlabroot/simulink/src/sfun_zc.c for an example.
mdlSetWorkWidths
The optional simulation only routine, mdlSetWorkWidths, is called after input
port width, output port width, and sample times of the S -function have been
determined to set any state- and work-vector sizes that are a function of the
input, output, and/or s ample times. T his routine is used to specify the nonzero
work vector widths via t he ma cros
ssNumContStates, ssSetNumDiscStates,
ssSetNumRWork, ssSetNumIWork, ssSetNumPWork, ssSetNumModes,and
ssSetNumNonsampledZCs.
An Example Involving a Pointer Work Vector
This exampl e opens a file and stores the FILE pointer in the pointer-work
vector.
Thestatementbelow,includedinthe
mdlInititalizeSizes function,indicates
that the pointer-work vector is to contain one element:
ssSetNumPWork(S, 1) /* pointer-work vector */
The code below uses the pointer-work vector to store a FILE pointer, returned
from the standard I/O function,
fopen:
#define MDL_START /* Change to #undef to remove function. */
#if defined(MDL_START)
static void mdlStart(real_T *x0, SimStruct *S)
{
FILE *fPtr;
void **PWork = ssGetPWork(S);
fPtr = fopen("file.data", "r");
PWork[0] = fPtr;
}
#endif /* MDL_START */
Vedere la pagina 89
1 2 ... 85 86 87 88 89 90 91 92 93 94 95 ... 209 210

Commenti su questo manuale

Nessun commento