I am trying to copy a boost::multi_array of std::complex values to an mxArray so I can write the values out to MATLAB .mat file. When I load the .mat file into MATLAB, it only has the real portions of the data and none of the imaginary portions. Here is a code snippet showing what I am doing.
boost::multi_array<std::complex<double>, 3> SAP_max_combined_complex(boost::extents[1][1][1], boost::fortran_storage_order());
// Later in the code
SAP_max_combined_complex.resize(boost::extents[xDim][yDim][zDim]);
// The multi_array is populated correctly - this has been verified
mwSize numDims = SAP_max_combined_complex.num_dimensions();
mwSize outputSizes[3] = {SAP_max_combined_complex.shape()[0], SAP_max_combined_complex.shape()[1], SAP_max_combined_complex.shape()[2]};
mxArray* outputData = mxCreateNumericArray(numDims, outputSizes, mxDOUBLE_CLASS, mxCOMPLEX);
memcpy(mxGetData(outputData), (void*) SAP_max_combined_complex.data(), (sizeof(std::complex<double>) * SAP_max_combined_complex.num_elements()));
// I then write the mxArray to the file with
matPutVariable(mpMatFile, fieldName.toStdString().c_str(), outputData);
Also of interesting note is if when I make the memcpy call, the deallocation of SAP_max_combined_complex crashes when I terminate my application. If I comment out the memcpy call, the deallocation works properly (or at least doesn't crash).
Any ideas what I am doing wrong? Thanks!