python有什么库可以 从fig文件中读取数据,使用Python来自MATLAB .fig文件的数据?

Does anyone know of any methods of extracting the data from a MATLAB fig file using Python? I know these are binary files but the methods in the Python Cookbook for .mat files http://www.scipy.org/Cookbook/Reading_mat_files don't seem to work for .fig files...

Thanks in advance for any help,

Dan

解决方案

.fig files are .mat files (containing a struct), see

http://undocumentedmatlab.com/blog/fig-files-format/

As the reference you give states, structs are only supported up to v7.1:

http://www.scipy.org/Cookbook/Reading_mat_files

So, in MATLAB I save using -v7:

plot([1 2],[3 4])

hgsave(gcf,'c','-v7');

Then in Python 2.6.4 I use:

>>> from scipy.io import loadmat

>>> x = loadmat('c.fig')

>>> x

{'hgS_070000': array([[]], 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([[]], dtype=object), '_fieldnames': ['type', 'handle', 'properties', 'children', 'special'], 'type': array([u'figure'], dtype=']], dtype=object), 'special': array([], shape=(1, 0), dtype=float64)}

Where I used .__dict__ to see how to traverse the structure. E.g. to get XData and YData I can use:

>>> 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)

Showing that I'd used plot([1 2],[3 4]) in MATLAB (the child is the axis and the grandchild is the lineseries).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值