使用hdf5storage从Python创建.v7.3的.mat文件
有没有办法从Python创建.mat v7.3文件?我已经能从Python创建hdf5文件了,但不知道怎么把它们转换成.mat v7.3文件。
我找到一个叫做 hdf5storage 的包,但我不知道怎么使用它。
1 个回答
2
示例(需要 Python 版本大于等于 2.6,并且安装 NumPy 和 h5py 版本大于等于 2.1 的包):
import hdf5storage # get code on https://pypi.python.org/pypi/hdf5storage/0.1.3
matcontent = {}
matcontent[u'some_numbers'] = [10, 50, 20] # each key must be a unicode string
hdf5storage.write(matcontent, '.', 'test.mat', store_python_metadata=False, matlab_compatible=True)
在 Matlab 中:
如果你想在 Matlab 中使用矩阵而不是单元数组:
import hdf5storage # get code on https://pypi.python.org/pypi/hdf5storage/0.1.3
import numpy as np
matcontent = {}
matcontent[u'some_numbers'] = np.array([10, 50, 20]) # each key must be a unicode string
hdf5storage.write(matcontent, '.', 'test2.mat', matlab_compatible=True)
你会注意到,第二个例子要快得多(快了超过十倍)。
更一般来说,可以参考 数据存储匹配 的文档: