在C

时间:2018-01-25 16:15:57

标签: c matlab

您好我正在将matlab代码转换为C.在此过程中,我需要阅读一些.mat文件。读取.mat文件字段,将它们保存到数组中然后处理它。 我见过一些例子here

这里他们使用了matlab提供的api。有没有办法在没有api的简单C中做到这一点?

更新: 我只是根据建议用简单的代码尝试了api:

#include "mat.h"
void matread_Cell(const char *file, const char *FieldName, int CellIndex)
{
    printf("\n From matread_cell Reading matfile %s...\n\n", file);
    MATFile* pmat = matOpen(file, "r");

    if (pmat == NULL) {
      printf("Error opening file %s\n", file);
      return;
    }
}

遗憾的是它无法识别MATFile或matOpen。错误说

  

对“matOpen”的未定义引用   块引用

我从extern / include / mat.h目录复制了mat.h,包括matrix.h和tmwtypes.h。

1 个答案:

答案 0 :(得分:1)

Matlab documents their file format. If you had a lot of time on your hands, you could rewrite your own parser from the spec.

But, I would say the API is simple C, and doing it without the API is the complicated way of doing it.