0
votes

I have a bunch of Matlab structures which have been generated from matlab R2018b version 9.5. The structure contains 3 fields:

  1. A Matrix of double size: 6942x6092
  2. A matrix of double size: 6942x1
  3. A matrix of cell size: 1x6092 (the content of the cells are string)

I would like to find a way to load this structure and access the three different elements in python 3.7. I have tried many ways but I never managed to load the structure and been able to access the 3 elements of the structure. For reproducing the structure in matlab:

struct.values = ones(6942,6092);
struct.dates = ones(6942,1);
struct.id = cell(1,6092);
struct.id(:) = {'x1'};
save('struct','struct');

It is then saved as a .mat file.

1
Are you asking how to load a .mat file in python? See h5py, and this answer. - Dev-iL
The answer unfortunately does work in that case. I get the error: "Unable to open file (file signature not found)". I am able to load simple matrices but if you read carefully my question, i am talking about matlab structure. So yes it is a .mat file but containing a structure. - Tulkkas

1 Answers

0
votes

Dev-iL was basically right, you can load structures with scipy.io.loadmat, not only matrices. See here:

import scipy.io as sio
container = sio.loadmat('struct.mat')
values = container['struct']['values'][0,0]