Matfile in c ausgeben
-
hallo ich hab ein problem ich hab eine matlab datei in der 3 2Dimensionale arrays mit double werten sind. das einlesen der datei stimmt auch und die dimension gibt er mir auch die richtige an. ich würde mir jetzt gerne mal die einzelnen werte des arrays ausgeben lassen um zu überprüfen ob alles stimmt.doch das klappt überhaupt nicht:-(habt ihr eine idee wie ich das am besten machen könnte. vielen dank schon mal für eure hilfe:-)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mat.h"
#include <mex.h>
#include <math.h>
MATFile *pmat;
const char **dir;
const char *file = "C:\\Documents and Settings\\g41465\\Desktop\\Akustikmessung_3E0400D1001T04_2011_10_29_19_3_26_1.mat";
const char *name;
int ndir,total_num_of_elements;
int i,j,m,l,pr;
int diagnose(const char file) {
/
* Open file to get directory
*/pmat = matOpen(file, "r");
if (pmat == NULL) {
printf("Error opening file %s\n", file);
return(1);
}dir = (const char **)matGetDir(pmat, &ndir);
if (dir == NULL) {
printf("Error reading directory of file %s\n", file);
return(1);
} else {
printf("Directory of %s:\n", file);
for (i=0; i < ndir; i++)
printf("%s\n",dir[i]);
}
mxFree(dir);/* In order to use matGetNextXXX correctly, reopen file to read in headers. */
if (matClose(pmat) != 0) {
printf("Error closing file %s\n",file);
return(1);
}
pmat = matOpen(file, "r");
if (pmat == NULL) {
printf("Error reopening file %s\n", file);
return(1);
}/* Get headers of all variables */
printf("\nExamining the header for each variable:\n");
for (i=0; i < ndir; i++) {
pa = matGetNextVariableInfo(pmat, &name);
if (pa == NULL) {
printf("Error reading in file %s\n", file);
return(1);
}
/* Diagnose header pa */
printf("According to its header, array %s has %d dimensions\n",
name, mxGetNumberOfDimensions(pa));
total_num_of_elements =mxGetNumberOfElements(pa);
printf("size is %d\n",total_num_of_elements);
l= mxGetN(pa);
printf("die Spaltenanzahl ist %d\n",l);
m= mxGetM(pa);
printf("die Zeilenzahl ist %d\n",m);
if (mxIsFromGlobalWS(pa))
printf(" and was a global variable when saved\n");
else
printf(" and was a local variable when saved\n");
mxDestroyArray(pa);
}/* Reopen file to read in actual arrays. */
if (matClose(pmat) != 0) {
printf("Error closing file %s\n",file);
return(1);
}
pmat = matOpen(file, "r");
if (pmat == NULL) {
printf("Error reopening file %s\n", file);
return(1);
}/* Read in each array. */
printf("\nAusgabe jedes Arrays:\n");}
-
Dieser Thread wurde von Moderator/in SeppJ aus dem Forum C++ (auch C++0x und C++11) in das Forum C (C89 und C99) verschoben.
Im Zweifelsfall bitte auch folgende Hinweise beachten:
C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?Dieses Posting wurde automatisch erzeugt.