Problem extracting data out of a variable of mat file in C++
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have to extract the data out of a variable(double array) of a mat file for use in my C++ code.I have tried the mxGetPr, mxGetVariable and mxGetData functions but they do not seem to work.I am able to read the mat file and even get the variable's name and no. of rows and columns but I haven't been able to extract data.Please help me out ,need urgent help!!
2 comentarios
James Tursa
el 26 de Jun. de 2012
Please post you code so we can point out the errors and suggest corrections.
Respuestas (1)
James Tursa
el 28 de Jun. de 2012
Your incorrect code:
/*Get Variable*/
pa = matGetVariable(pmat, file);
The 2nd argument is supposed to be the variable name, not the file name. E.g.,
/*Get Variable*/
pa = matGetVariable(pmat, dir[i]);
Then you can get at the data using mxGetPr(pa) etc. Just be sure not to free dir before you are done with it. And when you are done with it, free each dir[i] first since all of these strings are dynamically allocated also.
9 comentarios
Ketan
el 1 de Jul. de 2012
The %d format specifier indicates an integer argument, but I do not think the compiler converts the double *pr to int.
Try casting *pr from a double to an int datatype. For example:
...%d\n",(int)(*pr));
You only see one element because you are not iterating over the #elements in the array (the variable l).
This stack overflow article goes into some detail regarding the printf issue:
Ver también
Categorías
Más información sobre File Operations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!