Skip to content
Advertisement

Data from a MATLAB .fig file using Python?

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

Advertisement

Answer

.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:

JavaScript

Then in Python 2.6.4 I use:

JavaScript

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

JavaScript

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

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement