Set complex data elements in mxDOUBLE_CLASS
array
#include "matrix.h" int mxSetComplexDoubles(mxArray *pa, mxComplexDouble *dt);
Use mxSetComplexDoubles
to set mxComplexDouble
data in the specified array.
All mxCreate
* functions allocate heap space to hold data.
Therefore, you do not ordinarily use this function to initialize the elements of an
array. Rather, call the function to replace existing values with new values.
This function does not free memory allocated for existing data. To free existing
memory, call mxFree
on the pointer returned by
mxGetComplexDoubles
.
Refer to the arrayFillSetPr.c
example in the
folder which copies existing data into an matlabroot
/extern/examples/refbookmxArray
. The data in the
example is defined as mxDouble
. You can use this example as a pattern
for any C numeric type, including complex. Suppose that you have an array with these
values.
2.0 + 3.0i 3.0 + 4.0i
To modify this example for complex mxDouble
data:
Declare data variables
mxComplexDouble *dynamicData; const mxComplexDouble data[] = {{2.0, 3.0}, {3.0, 4.0}};
Call mxCreateNumericMatrix
with the
mxCOMPLEX
argument
Replace mxSetDoubles
with
mxSetComplexDoubles
to put the C array into an
mxArray
This function is available in the interleaved complex API. To build
myMexFile.c
using this function, type:
mex -R2018a myMexFile.c