C中使用MATLAB的mat文件

 C中訪問Matlab數據文件Mat的方式:

mat數據格式是matlab的數據存儲的標準格式。  

 

(1)首先將Mat.h所在的includes文件夾加到Vs2005的include配置中:

Tools-Options-Projects and Solutions-VC++ Directories

在show derectories for:中選擇includes file

將Matlab安裝目錄下的extern/include添加到其中。

(2)#include<mat.h>

(3)常見函數:

 

  matopen       打開mat文件  
  matclose       關閉mat文件  
  magetfp        取得mat文件的c語言句柄  
  matGetArray 取得一個數組  

 

 

 

 

/*
 * Open a MAT-file "filename" using mode "mode".  Return
 * a pointer to a MATFile for use with other MAT API functions.
 *
 * Current valid entries for "mode" are
 * "r"    == read only.
 * "w"    == write only (deletes any existing file with name <filename>).
 * "w4"   == as "w", but create a MATLAB 4.0 MAT-file.
 * "w7.3" == as "w", but create a MATLAB 7.3 MAT-file.
 * "u"    == update.  Read and write allowed, existing file is not deleted.
 *
 * Return NULL if an error occurs.
 */
EXTERN_C MATFile * matOpen(const char *filename, const char * mode);

 

/*
 * Close a MAT-file opened with matOpen.
 *
 * Return zero for success, EOF on error.
 */
EXTERN_C int matClose(MATFile *pMF);


/*
 * Write array value with the specified name to the MAT-file, deleting any
 * previously existing variable with that name in the MAT-file.
 *
 * Return zero for success, nonzero for error.
 */
EXTERN_C int matPutVariable(
           MATFile * pMF,
           const char * name,
           const mxArray * pA
           );

 

/*
 * Read the array value for the specified variable name from a MAT-file.
 *
 * Return NULL if an error occurs.
 */
EXTERN_C mxArray * matGetVariable(MATFile * pMF, const char * name);

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章