Beruflich Dokumente
Kultur Dokumente
wsum.m:
function summe = wsum(x, a, b)
summe = a*x(1)+b*x(2);
Programmierung
• als m.File oder
• in C (kompilieren mit mex)
• gleicher Baustein
M S-Function
interner Aufruf
t Current time
x State vector
u Input vector
flag Integer value that indicates the task to be performed by the S-function
Parameterübergabe:
Argumente nach t,x,u,flag
#include "simstruc.h"
ssSetNumContStates(S, 0);
ssSetNumDiscStates(S, 0);
if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0, 2);
ssSetInputPortDirectFeedThrough(S, 0, 1);
C S-Function
ssSetOptions(S, 0);
}
...
static void mdlOutputs(SimStruct *S, int_T tid)
{
const real_T *u = (const real_T*) ssGetInputPortSignal(S,0);
real_T *y = ssGetOutputPortSignal(S,0);
y[0] = a*u[0]+b*u[1];
}
#ifdef MATLAB_MEX_FILE
#include "simulink.c"
#else
#include "cg_sfun.h"
#endif
Teil 4: Building
>> mex cwsum.c
C S-Function (Level 2)