Problems with the Matlab C API, matOpen applied to structures
4 次查看(过去 30 天)
显示 更早的评论
I'm having some troubles writing c-code to read a saved .mat file containing a structure. I have code that calls the subfunction:
--------------------------------------
const char *filePtr = "OpenMATLABTest.mat";
printf("File Location: %s \n\n", filePtr);
int statusLoad = CryoSimLoad(filePtr);
printf("Status is: %i \n\n", statusLoad);
--------------------------------------
and the subfunction itself:
--------------------------------------
/* CryoSimLoad.c
*/
#include <stdio.h>
#include <math.h>
#include "mat.h"
#include "CryosimSimple.h" /* Model's header file */
#include "rtwtypes.h" /* MathWorks types */
#define BUFSIZE 256
int CryoSimLoad() {
MATFile *mfPtr; /* MAT-file pointer */
mxArray *aPtr; /* mxArray pointer */
/* */
mfPtr = matOpen("OpenMATLABTest.mat", "r");
if (mfPtr == NULL) {
printf("Error opening file \n");
return(1);
}
if (matClose(mfPtr) != 0) {
printf("Error closing file\n");
return(EXIT_FAILURE);
}
mxDestroyArray(aPtr);
return(0);
}
------------------------------------------------------------------
when there is a structure in the saved file I get a : "RUN FAILED (exit value 1)" , if there isn't a structure (just arrays and scalars) it loads.
Does anyone have any suggestions?
2 个评论
James Tursa
2013-5-16
编辑:James Tursa
2013-5-16
1) You call with an argument
CryoSimLoad(filePtr)
but the function doesn't have any arguments
int CryoSimLoad() { etc
2) I don't see a RUN FAILED message string in your code, so I don't know exactly where you think the error is happening.
3) You call mxDestroyArray(aPtr) with an uninitialized pointer argument, so I would expect this to bomb.
I suspect you did some code snipping and simplification for posting purposes, but you have cut out too much for us to see what is going on and introduced errors that are probably not there in your actual code. Please edit your post to correct this.
回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!