Problems with the Matlab C API, matOpen applied to structures
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
James Tursa
le 16 Mai 2013
Modifié(e) : James Tursa
le 16 Mai 2013
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.
Réponses (0)
Voir également
Catégories
En savoir plus sur Write C Functions Callable from MATLAB (MEX Files) dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!