Python Forum
Importing matlab cell array (.mat) into a python list - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: Importing matlab cell array (.mat) into a python list (/thread-6305.html)



Importing matlab cell array (.mat) into a python list - scanato - Nov-15-2017

Hi! I'm trying to import a .mat file that contains a cell array. In matlab I did this:
a={'element1';'element2';'element3'};
save('m.mat','-v7','a')

I used '-v7' because, in python, I use 'scipy.io' and 'loadmat' that can be used only with version 7. In python:
import scipy.io as sio
i=sio.loadmat('m.mat')
i.keys()

And I get:
dict_keys(['__header__', '__version__', '__globals__', 'a'])

Finally, I use the key 'a':
k=i['a']

In the variable explorer I get k, that is a object type but I can't access to its elements. How can I convert it to a list?
[Image: KXnVn.jpg]

Thank you