2

If I have some X vs Y data saved in a Matlab .fig file, is there a way to extract that data in Python? I've tried using the method shown in a previous discussion, but this does not work for me. I have also tried to open the files using h5py and PyTables, since .mat files are actually HDF5 files now, but this results in an error where a valid file signature can't be found.

Currently I'm trying to do this with the Anaconda distribution of Python 3.4.

EDIT: I managed to figure out something that works, but I don't know why. This has me worried something might break in the future and I won't be able to debug it. If anyone can explain why this works, but the method in the old discussion doesn't I'd really appreciate it.

from scipy.io import loadmat
d = loadmat('linear.fig', squeeze_me=True, struct_as_record=False)
x = d['hgS_070000'].children.children.properties.XData
y = d['hgS_070000'].children.children.properties.YData
Community
  • 1
  • 1
Matt Crank
  • 21
  • 1
  • 4

1 Answers1

0

The best way I can think of is using any of the Matlab-Python bridge (such as pymatbridge).

You can call Matlab code directly on python files and transform the data from one to the other. You could use some Matlab code to load the fig and extract the data and then convert the numerical variables to python arrays (or numpy arrays) easily.

Ander Biguri
  • 35,140
  • 11
  • 74
  • 120
  • This is an interface, so doesn't that mean it also requires Matlab as well? A goal of my project is to be Matlab independent. It's just that the relevant data that needs to be analyzed is stored in .fig files currently since that was convenient at the time. – Matt Crank Apr 10 '15 at 20:00
  • @MattCrank yeah, indeed you need Matlab. I assumed you could use it as you where using fig images. Hope you can get a way! good luck – Ander Biguri Apr 10 '15 at 22:06