matlab 行 读取文件 跳过_matlab生成的mat文件, scipy.io无法读取

在调试过程中遇到Python使用scipy.io.matlab.loadmat无法读取MATLAB R2019a生成的-v6格式.mat文件,原因是版本问题和文件格式。MATLAB的_level 5 MAT-file format_不同于_HDF5格式_,后者是更先进的存储方式。Python可以借助h5py库读取HDF5格式的.mat文件。
摘要由CSDN通过智能技术生成

起因:

votenet调试过程中:

python sunrgbd_data.py --gen_v1_data

Traceback (most recent call last):
  File "sunrgbd_data.py", line 332, in <module>
    save_votes=True, num_point=50000, use_v1=True, skip_empty_scene=False)
  File "sunrgbd_data.py", line 231, in extract_sunrgbd_data
    pc_upright_depth = dataset.get_depth(data_idx)
  File "sunrgbd_data.py", line 70, in get_depth
    return sunrgbd_utils.load_depth_points_mat(depth_filename)
  File "/d/v/sunrgbd/sunrgbd_utils.py", line 196, in load_depth_points_mat
    depth = sio.loadmat(depth_filename)['instance']
  File "/usr/local/lib/python3.6/dist-packages/scipy/io/matlab/mio.py", line 142, in loadmat
    matfile_dict = MR.get_variables(variable_names)
  File "/usr/local/lib/python3.6/dist-packages/scipy/io/matlab/mio5.py", line 272, in get_variables
    hdr, next_position = self.read_var_header()
  File "/usr/local/lib/python3.6/dist-packages/scipy/io/matlab/mio5.py", line 219, in read_var_header
    raise ValueError("Did not read any bytes")
ValueError: Did not read any bytes

matlab版本:

我用的是R2019a

R: release的意思, 每年发布几次

Version才是版本号

3e2848a738aa7b560d3249a570bb9b5c.png

7f94f4ffa4e943232e7685ba5ec59dbf.png

In matlab comand lind:

>> save('wf_1.mat', 'p', '-v6')

in python:

wf = scipy.io.matlab.loadmat('./wf_1.mat')

616e4637170328aa6411efc63836c301.png

Why the '_header_' is 5.0 MAT-file, instead of 6.0 MAT-file when I save('wf_1.mat', 'p', '-v6') ?

5.0 MAT-file是Level 5 MAT-file format的意思,

'-v5','-v6' and '-v7' refer to different capabilities on the same format.

Version 7.3 MAT-files :

use an HDF5 based format that requires some overhead storage to describe the contents of the file.

HDF5 based format 比 Level 5 MAT-file format(应该就是下图说的own binary form) 先进

Error with loadmat in scipy: could not read bytes

821306d22aaf5af25a2ea94986aa471e.png
The Level 5 MAT-file format
supports all the array types supported in MATLAB Versions 5 and up, including multidimensional
numeric arrays, character arrays, sparse arrays, cell arrays, structures, and objects. 


The Level 4 MAT-file format is a simpler format, but it only supports two-dimensional matrices and
character strings. 
Why does my 'MAT-File Header Summary' include the 'MATLAB 5.0 MAT-file' header message when I try to save my ...​www.mathworks.com

最后发现这货损坏

335cac7e0a38c79b49330f9f066a294c.png

(但文件大小看着和其他mat文件差不多)

matlab命令行读mat文件最直接

9bffdd680765f88c50852971746c5118.png

python读mat文件:

HDF5格式 :

>>> import h5py
>>> f = h5py.File('test.mat')
>>> list(f.keys())

How to read a v7.3 mat file via h5py?​stackoverflow.com
ddb65ce1d5f7408c1293a5d1a12df527.png

level 5 MAT格式:

my_variable = scipy.io.matlab.loadmat('/v/sunrgbd/sunrgbd_trainval/depth/007454.mat')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值