I have been writing an c s-function block for simulink.I want my output as an array
//
FILE *datafile;
datafile = fopen("datafile.dat","r");
pwork[0] = datafile;
//
//
static void mdlOutputs(SimStruct *S, int_T tid)
{
real_T *y = ssGetOutputPortSignal(S,0);
real_T *a;
real_T *b;
real_T *c;
void** pwork = ssGetPWork(S);
fscanf(pwork[0],"%f %f %f",y[0],y[1],y[2]);
}
//
But it doesn’t work like that.I guess the problem is with allocating y[1] and y[2]..
I don’t know about Matlab, but I do know that the arguments to a
scanfcall should be pointers, and unlessreal_Tis typedefed as a pointer already it will not work.Besides, you are using
fscanfwhich is for reading from aFILEpointer.I don’t know if this will work or not, by try this instead: