Moving Complex Data to a .mat file from a C Program
Mostrar comentarios más antiguos
[EDIT: 20110621 12:22 CDT - reformat - WDR]
I'm running Matlab r2010a on a Redhat Linux platform compiling with gcc.
I want to move complex data in C into a .mat file. I've successfully moved real data with the following.
_realDat = mxCreateDoubleMatrix(numRow, 1, mxREAL) ;
mRealP = mxGetPr(realDat) ;
memcpy ((void *) mRealP, (void *) rArrayP, numRow * sizeof(real)) ;
I understand mxGetPr and mxGetPi get pointers to the the real and imaginary part of complex data in a mxArray. So, if I have an array of complex data in C, cArrayP, how do I move it to an mxArray of complex data, compData? Do I use both mxGetPr and mxGetPi? If I do, how do I use two memcpy statements? Do I need to create two additional arrays in C using the creal and cimag functions to get the real and imaginary parts of the complex data? Is there a way to move the complex data from a C array into an mxArray in one fell swoop?
_compData = mxCreateDoubleMatrix(numRow, numCol, mxCOMPLEX);
mCompPr = mxGetPr(compData); ?? or mCompPi = mxGetPi(compData); ?? or both?
memcpy ((void *) which pointer?, (void *) cArrayP or creal array or cimag array or both?, correct size);
??
I'm sorry the C statements run together ... I don't know how to fix that. [Fixed - WDR]
Thanks,
Tom
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre C Shared Library Integration en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!