【问题标题】:"Can only read from Matlab level 5 MAT-files"“只能从 Matlab 5 级 MAT 文件中读取”
【发布时间】:2021-06-12 22:44:08
【问题描述】:

我正在尝试使用mat4py 将文件从 Matlab 加载到我的 python 中。 我有以下错误

ParseError: Unexpected field name length: 43 

使用时

import h5py
from numpy import ndarray
data_py = loadmat("data.mat")

我听从了here的建议

所以,

explore_v73_matfile(file_name="data.mat", fptr=None, path=r"C:/Users/...mypath/data_folder")
data_100E = loadmat("data.mat")

但是,现在我有一个新错误:

ParseError: Can only read from Matlab level 5 MAT-files

很遗憾,我不能分享data.mat。有没有人知道如何用我能提供的少量信息来解决这个问题?

【问题讨论】:

    标签: python matlab file file-conversion


    【解决方案1】:

    MAT-File Format documentation (PDF) 表示 MAT-File 的最后一个二进制结构是“Level 5 MAT-files”。

    本文档描述了 MATLAB Level 4 的内部格式和 5 级 MAT 文件。 4 级 MAT 文件与以下版本兼容 MATLAB 最高版本 4。5 级 MAT 文件与 MATLAB 兼容 版本 5 及更高版本。

    loadmat.py 函数在第 425-429 行的注释中指出(截至 2021 年 3 月):

    # Check mat file format is version 5
    # For 5 format we need to read an integer in the header.
    # Bytes 124 through 128 contain a version integer and an
    # endian test string
    

    如果您的 MAT 文件不兼容,loadmat.py 会输出错误。

     if maj_val != 1:
            raise ParseError('Can only read from Matlab level 5 MAT-files')
    

    可能您的 MAT 文件是很久以前创建的,或者是使用旧的 matlab 版本创建的,无法再使用 mat4py 读取。

    您应该尝试使用 matlab 读取您的 MAT 文件并再次保存。

    【讨论】:

      猜你喜欢
      • 2012-04-16
      • 2021-02-23
      • 2016-01-25
      • 1970-01-01
      • 2018-11-04
      • 2014-06-07
      • 2014-12-01
      • 2018-08-04
      • 1970-01-01
      相关资源
      最近更新 更多