Python Forum
Importing matlab cell array (.mat) into a python list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Importing matlab cell array (.mat) into a python list
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem of converting Matlab code to python DongyanZ 2 1,376 Feb-03-2023, 01:04 PM
Last Post: jefsummers
  Turn list of arrays into an array of lists Cola_Reb 6 1,663 Jul-20-2022, 06:55 PM
Last Post: Cola_Reb
  Convolution "same" in Python doesn't work as Matlab claw91 4 3,687 Oct-01-2020, 08:59 AM
Last Post: claw91
  Python equivalent of Matlab code kwokmaster 5 6,999 Apr-03-2020, 12:02 AM
Last Post: scidam
  Python read Excel cell data validation anantpatil 0 4,107 Jan-31-2020, 04:57 PM
Last Post: anantpatil
  Is there similar function to lsqnonlin (in matlab) in python? Jay_Nerella 1 5,881 Nov-11-2019, 08:40 AM
Last Post: feli_x
  Slicing String cell by cell Vigneshkumarsakthivel 0 2,362 Sep-02-2018, 05:59 PM
Last Post: Vigneshkumarsakthivel
  Matlab to Python Ariane 6 6,999 Jun-14-2018, 12:08 PM
Last Post: Ariane
  Convert element of list to integer(Two dimentional array) zorro_phu 3 4,635 Jun-12-2018, 04:49 AM
Last Post: zorro_phu
  How to use .m matlab file in python ? sameer 5 15,291 May-10-2018, 09:39 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020