linux c 读取mat文件格式,linux下 C++ 读取mat文件 MATLAB extern cyphon scipy 未完待续

/** MAT-file diagnose program

*

* See the MATLAB API Guide for compiling information.

*

* Calling syntax:

*

* matdgns

*

* It will diagnose the MAT-file named .

*

* This program demonstrates the use of the following functions:

*

* matClose

* matGetDir

* matGetNextVariable

* matGetNextVariableInfo

* matOpen

*

* Copyright 1984-2003 The MathWorks, Inc.*/

/*$Revision: 1.8.4.1 $*/#include#include#include"mat.h"

int diagnose(const char *file) {

MATFile*pmat;const char **dir;const char *name;intndir;inti;

mxArray*pa;

printf("Reading file %s...\n\n", file);/** Open file to get directory*/pmat= matOpen(file, "r");if (pmat ==NULL) {

printf("Error opening file %s\n", file);return(1);

}/** get directory of MAT-file*/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,int( mxGetNumberOfDimensions(pa)));if(mxIsFromGlobalWS(pa))

printf("and was a global variable when saved\n");elseprintf("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("\nReading in the actual array contents:\n");for (i=0; i

pa= matGetNextVariable(pmat, &name);if (pa ==NULL) {

printf("Error reading in file %s\n", file);return(1);

}/** Diagnose array pa*/printf("According to its contents, array %s has %d dimensions\n",

name,int(mxGetNumberOfDimensions(pa)));if(mxIsFromGlobalWS(pa))

printf("and was a global variable when saved\n");elseprintf("and was a local variable when saved\n");

mxDestroyArray(pa);

}if (matClose(pmat) != 0) {

printf("Error closing file %s\n",file);return(1);

}

printf("Done\n");return(0);

}int main(int argc, char **argv)

{intresult;if (argc > 1)

result= diagnose(argv[1]);else{

result= 0;

printf("Usage: matdgns ");

printf("where is the name of the MAT-file");

printf("to be diagnosed\n");

}return (result==0)?EXIT_SUCCESS:EXIT_FAILURE;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值