illegal use of type name mxArray

5 views (last 30 days)
Alex
Alex on 9 Sep 2013
Hello,
When I compile the following code, I get an error from the compiler:
int count_OK;
double *Gain_final = NULL;
double *freq_final = NULL;
// value of count_OK is defined
Gain_final = (double*)malloc(count_OK*sizeof(double));
freq_final = (double*)malloc(count_OK*sizeof(double));
// Fill arrays of variable size Gain_final, phase_final, freq_final
x_ptr_freq_final = mxCreateDoubleMatrix(1, count_OK, mxREAL);
memcpy(mxGetPr(x_ptr_freq_final), freq_final, sizeof(double)*count_OK);
x_ptr_gain_final = mxCreateDoubleMatrix(1, count_OK, mxREAL);
memcpy(mxGetPr(x_ptr_gain_final), Gain_final, sizeof(double)*count_OK);
mxArray *prhs[2] = {x_ptr_freq_final, x_ptr_gain_final};
The error of the compiler is the following:
Error time2freq.c: 430 illegal use of type name `mxArray'
Error time2freq.c: 430 unknown size for type `incomplete struct mxArray_tag defined at C:\Program Files (x86)\Matlab_R2010BSP2\extern\include\matrix.h 298'
Error time2freq.c: 430 operands of * have illegal types `incomplete struct mxArray_tag defined at C:\Program Files (x86)\Matlab_R2010BSP2\extern\include\matrix.h 298' and `incomplete struct mxArray_tag defined at C:\Program Files (x86)\Matlab_R2010BSP2\extern\include\matrix.h 298'
Error time2freq.c: 430 illegal expression
Error time2freq.c: 430 lvalue required
Warning time2freq.c: 430 possible usage of prhs before definition
Error time2freq.c: 430 syntax error; found `x_ptr_freq_final' expecting `;'
Warning time2freq.c: 430 Statement has no effect
Error time2freq.c: 430 syntax error; found `}' expecting `;'
Error time2freq.c: 431 illegal use of type name `mxArray'
When the arrays Gain_final and freq_final are not defined dynamically with malloc, everything works. But as the size of these arrays change, I need to use malloc.
Thank you for your help if you have any idea:)

Accepted Answer

Jan
Jan on 9 Sep 2013
If this is a C-file, definitions of variables must appear before the first command in the function. So try to move "mxArray *prhs[2];" to the top of the function.
  2 Comments
Alex
Alex on 9 Sep 2013
Yep, now it works. Thank you :D
Jan
Jan on 9 Sep 2013
Then the error message of the compiler is not useful, although it would be easy to detect the reason of the problem automatically. Shame on the manufacturer of the compiler.

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!