您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

使用Python来自MATLAB .fig文件的数据?

使用Python来自MATLAB .fig文件的数据?

.fig文件是.mat文件(包含结构),请参见 http://undocumentedmatlab.com/blog/fig-files- format/

作为状态的参考,仅在v7.1之前支持结构:http ://www.scipy.org/Cookbook/Reading_mat_files

因此,在MATLAB中,我使用-v7保存:

plot([1 2],[3 4])
hgsave(gcf,'c','-v7');

然后在Python 2.6.4中,我使用:

>>> from scipy.io import loadmat
>>> x = loadmat('c.fig')
>>> x
{'hgS_070000': array([[<scipy.io.matlab.mio5.mat_struct object at 0x1500e70>]], dtype=object), '__version__': '1.0', '__header__': 'MATLAB 5.0 MAT-file, Platform: MACI64, Created on: Fri Nov 18 12:02:31 2011', '__globals__': []}
>>> x['hgS_070000'][0,0].__dict__
{'handle': array([[1]], dtype=uint8), 'children': array([[<scipy.io.matlab.mio5.mat_struct object at 0x1516030>]], dtype=object), '_fieldnames': ['type', 'handle', 'properties', 'children', 'special'], 'type': array([u'figure'], dtype='<U6'), 'properties': array([[<scipy.io.matlab.mio5.mat_struct object at 0x1500fb0>]], dtype=object), 'special': array([], shape=(1, 0), dtype=float64)}

.__dict__以前在哪里查看如何遍历结构。例如XDataYData我可以使用:

>>> x['hgS_070000'][0,0].children[0,0].children[0,0].properties[0,0].XData
array([[1, 2]], dtype=uint8)
>>> x['hgS_070000'][0,0].children[0,0].children[0,0].properties[0,0].YData
array([[3, 4]], dtype=uint8)

证明我plot([1 2],[3 4])在MATLAB中使用过(孩子是轴,孙子是线系列)。

python 2022/1/1 18:40:32 有264人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶