有什么方法可以从 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 的文档:
关于python - 使用 hdf5storage 从 Python 创建 .mat v7.3 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23333978/