0

Im trying to convert a program from C++/MEX to just C++ using MATIO and I am wondering if MATIO has an equivalent to mxGetPr(cal) and mxGetPi(cal)? I see in the struct typedef struct matvar_t it has void *data filed

Here is how to write a complex double into a file:

char* fieldname = "MyComplexDoubleVariable";
double real = 4.2;
double imag = 1.5;
mat_complex_split_t mycomplexdouble = {&real, &imag};
size_t dim[2]={ 1, 1 };
matvar_t *variable = Mat_VarCreate(fieldname, MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dim, &mycomplexdouble, MAT_F_COMPLEX);
Mat_VarWrite(matfp,variable, MAT_COMPRESSION_NONE); //or MAT_COMPRESSION_ZLIB
Mat_VarFree(variable);

So working backwards I would think this would work mat_complex_split_t cal_complex=cal->data; but I get this error when compiling

error: conversion from ‘void*’ to non-scalar type ‘mat_complex_split_t’ requested
                 mat_complex_split_t cal_complex=cal->data;

Any help would be greatly appreciated.

Tyler
  • 13
  • 5

1 Answers1

0

Here is my code to read complex data from mat-file.
I think you should use static_cast to convert void * to specify type.

const mat_complex_split_t* xData = static_cast<const mat_complex_split_t*>(matVar->data);
const double* real = static_cast<const double*>(xData->Re);
const double* imag = static_cast<const double*>(xData->Im);
// Read 10 complex num
for (int i = 0; i < 10; ++i) {
     std::cout << real[i] << "+ 1j*"<< imag[i] << std::endl;
}