有什么方法可以从 Python 创建 .mat v7.3 文件吗?我已经设法从 Python 创建 hdf5 文件,但没有将它们转换为 .mat v7.3 文件。 我找到了一个名为 hdf5storage 的包裹但我不知道如何使用它。
请您参考如下方法:
示例(需要 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)
您会注意到,第二个示例要快得多 (>x10)。
更一般地说,请参阅 data storage matching 的文档:
