Seguendo this question che chiede (e risponde) come leggere i file .mat che sono stati creati in Matlab usando Scipy, voglio sapere come accedere ai campi nelle strutture importate.Come accedere ai campi in una struct importata da un file .mat usando loadmat in Python?
Ho un file in Matlab da cui posso importare uno struct:
>> load bla % imports a struct called G
>> G
G =
Inp: [40x40x2016 uint8]
Tgt: [8x2016 double]
Ltr: [1x2016 double]
Relevant: [1 2 3 4 5 6 7 8]
Ora voglio fare lo stesso in Python:
x = scipy.io.loadmat('bla.mat')
>>> x
{'__version__': '1.0', '__header__': 'MATLAB 5.0 MAT-file, Platform: PCWIN, Created on: Wed Jun 07 21:17:24 2006', 'G': array([[<scipy.io.matlab.mio5.mat_struct object at 0x0191F230>]], dtype=object), '__globals__': []}
>>> x['G']
array([[<scipy.io.matlab.mio5.mat_struct object at 0x0191F230>]], dtype=object)
>>> G = x['G']
>>> G
array([[<scipy.io.matlab.mio5.mat_struct object at 0x0191F230>]], dtype=object)
La domanda è: come posso accedere i membri della struttura G: Inp
, Tgt
, Ltr
e Relevant
, il modo in cui posso in Matlab?
Cosa fare di aiuto (G) e dir (G) dire (e lo stesso per G [0]) – Kimvais
Cosa succede se si utilizza 'x = scipy.io.loadmat (' bla.mat', struct_as_record = true) '? Vedi http://docs.scipy.org/doc/scipy/reference/generated/scipy.io.loadmat.html – unutbu