0

I'm working on porting code from Matlab into python, and I'm using numpy and scipy as the main libraries. I've run into an issue where I need to repopulate a class with data. In the Matlab code this data was all precomputed so that on subsequent runs, it wouldn't need to be calculated again. I'm trying to load the data in the object, but can't seem to access the elements I want.

Printing the contents after running scipy.io.loadmat gives me the following:

{'__function_workspace__': array([[ 0,  1, 73, ...,  0,  0,  0]], dtype=uint8), 
'None': MatlabOpaque([('TLib', 'MCOS', 'TexLib', [[3707764736L], [2L], [1L], [1L], [1L], [2L]])], 
dtype=[('s0', 'O'), ('s1', 'O'), ('s2', 'O'), ('arr', 'O')]), '__version__': '1.0', 
'__header__': 'MATLAB 5.0 MAT-file, Platform: PCWIN64, Created on: Thu Dec 12 17:40:42 2013', '__globals__': []}

I don't even see the properties I want to access, they all seem hidden. When I try to access parts of the above as dictionary elements, I don't see them either.

I'd like to avoid rewriting the Matlab code to recreate the objects if at all possible. Is there anyway to access the properties of a class using scipy?

EDIT

The class type I'm trying to load is called TexLib.

It contains:

  • ImW (316944x824 uint8)
  • ImW_G (316944x824 uint8)
  • Gr (struct), Masks (struct)
  • NormalizedTexSize (1x3 double)
  • NumTexs (double)
  • ShapeMeanTexSpace (1x178 double)
  • PreComputePoisson (1x80 cell)
  • TexDH (empty)
wbest
  • 611
  • 1
  • 6
  • 15
  • Could you add an example of the class structure in Matlab? What do you expect to see? – perimosocordiae Jan 27 '14 at 19:45
  • I've edited the question with the class properties as seen in variable viewer. Note that trying to access 'None' and then 'TexLib' doesn't yield anything. – wbest Jan 27 '14 at 21:31
  • Looks like someone else had the same problem: http://stackoverflow.com/questions/15512560/access-mat-file-containing-matlab-classes-in-python – perimosocordiae Jan 27 '14 at 21:35
  • Thanks, I must have missed that when I searched for similar questions earlier. – wbest Jan 27 '14 at 22:26
  • You can load MATLAB arrays and structures with `scipy.io`, but you can't load classes. structures become dictionaries. Matlab classes are incompatible with Python classes, and can't be ported via .mat files. – hpaulj Jan 28 '14 at 21:19

0 Answers0