Open a structure of substructures of matlab with python -
i have structure of substructures output of matlab file. every substructure has 4 variables 3 arrays. access every single value of data python.
does have idea on how can that? new in python. have installed numpy , scipy.
% ----matlab file example---- main_struct{ substruct1{atr1,atr2[1x64],atr3[50x64],atr4[50x64]} substruct2{atr1,atr2[1x64],atr3[50x64],atr4[50x64]} . . . substructn{atr1,atr2[1x64],atr3[50x64],atr4[50x64]} }
thanks in advance.
you can read matlab(.mat) files in python, try this:
from scipy.io import loadmat mat = loadmat('file.mat')
then access structure with:
my_struct = mat['variable_name_in_matlab']
after can do
>>> print my_struct.shape (1, 1) >>> val = my_struct[0,0] >>> print val ([[1.0]], [[2.0]]) >>> print val['field1'] [[ 1.]] >>> print val['field2'] [[ 2.]] >>> print val.dtype [('field1', '|o8'), ('field2', '|o8')]
you can see more details here
Comments
Post a Comment