C CODE Generation - Why does my code not terminate?

1 view (last 30 days)
Hello,
I generated some C code with the Matlab coder. I wrote a main script to run the functions I generated. I dont get any error messages while running my code. However the code wont terminate. I know this question is possibly very diffcult to ask, but did someone face similar difficulties and what are possible reasons that a generated code wont terminate while I did not had any problems with the orignal code in MATLAB? I generated more then 30 functions. I dont think, its a good idea to attach all of them here.
This is my main script:
void main(void)
{
static double x_data[1024];
double Results[18];
double dv[6];
double maxP_tmp;
int Fs;
double tol;
int x_size[1];
int i;
int j;
/* Initialize function 'EV_Code' input arguments. */
/* Initialize function input argument 'x'. */
for (i = 0; i <1024; i++) {
x_data[i] = 1;
}
x_data[3] = 1.2;
x_data[230] = 1.3;
x_data[443] = 1.7;
x_data[354] = 1.9;
x_data[146] = 1.6;
x_size[0]= 2;
maxP_tmp = 1.1;
dv[0] = 114.5;
dv[1] = 90.81;
dv[2] = 73.72;
dv[3] = 87.76;
dv[4] = 72.78;
dv[5] = 59.65;
Fs = 1000;
tol = 0.04;
EV_Code_X(x_data, x_size, maxP_tmp, Fs, dv, tol, Results);
EV_Code_X_terminate();
// return 0;
}
  8 Comments
Rik
Rik on 8 Mar 2021
I have restored the original question body from the Google cache. Don't remove it again.

Sign in to comment.

Answers (1)

Geoff Hayes
Geoff Hayes on 12 Feb 2021
Edited: Walter Roberson on 8 Mar 2021
HF - the code that you mention
for (i = 0; i <= coffset; i++) {
Xm0_data[i] = Xm0->data[(aoffset + 30 * i) - 1];
}
occurs before the while loop so the while isn't the problem. In this case, what is coffset initialized to? Is it a valid or reasonable integer? It seems to get initialized via Xm0 but all I see for this variable is that it is defined as
emxArray_real_T *Xm0;
and later initialized as
emxInit_real_T(&Xm0, 2);
but is that sufficient for
i = Xm0->size[0] * Xm0->size[1];
Xm0->size[0] = 30;
Xm0->size[1] = x_size[0] + 29;
emxEnsureCapacity_real_T(Xm0, i);
? Since i is being initialized before the size, I wonder if that is somehow corrupting the object.
  30 Comments
Geoff Hayes
Geoff Hayes on 14 Feb 2021
Why do you think that the program skipped the call to emxEnsureCapacity_real_T? Check the Xm0->allocatedSize to see what this value is. (I don't have the MATLAB coder so cannot test out your files.)

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!