Should this C code work?
int main() { mxArray* array_ptr; double start_real[6] = { 1.01, 2.02, 3.03, 4.04, 5.05, 6.06 }; double start_imag[6] = { 0.2, 0.3, 0.4, 0.5, 0.6, 0.7 }; array_ptr = mxCreateNumericMatrix(2, 3, mxSINGLE_CLASS, mxCOMPLEX);#ifdef MX_HAS_INTERLEAVED_COMPLEX mxComplexDouble* pc; pc = mxGetComplexDoubles(array_ptr); memcpy(&pc->real, start_real, 6 * sizeof(double)); memcpy(&pc->imag, start_real, 6 * sizeof(double));#else memcpy(mxGetPr(array_ptr), start_real, 6 * sizeof(double)); memcpy(mxGetPi(array_ptr), start_imag, 6 * sizeof(double));#endif return 0;}
When I call mxGetComplexDoubles, the value returned is NULL! I think that is by design because the array is currently empty. However, how do I fill my array given the old way (with mxGetPr and mxGetPi) vs. the new way… whatever that new way is…?
I keep reading https://www.mathworks.com/help/matlab/matlab_external/upgrade-mex-files-to-use-interleaved-complex.html for help, but I don't understand why the call to mxGetComplexDoubles is NULL! Please help! Thanks!
Best Answer