Info

This question is closed. Reopen it to edit or answer.

Simulink model cannot read from TXT file after being built into executable.

1 view (last 30 days)
I used s-function block in my simulink model calling a C file, in which it should read from a TXT file. Here's the code of: static void mdlOutputs(SimStruct *S, int_T tid)
const real_T *u = (const real_T*) ssGetInputPortSignal(S,0);
real_T *y = ssGetOutputPortSignal(S,0);
char line[80];
fr = fopen ("C:\\filename.txt", "r");
while(fgets(line, 80, fr) != NULL)
{
scanf ("%c",line);
}
y[0] = (int)line[0];
y[1] = (int)line[1];
y[2] = (int)line[2];
y[3] = (int)line[3];
y[4] = (int)line[4];
fclose(fr);
It runs with no problem as a model. However, after I compiled it into executable using real-time workshop(matlab coder), it cannnot read from that file anymore. How should I fix that?

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!