Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python read mat file datetime array

I'm trying to read a mat file using python's scipy io library, specifically a struct that contains an array of datetimes but it's not getting the information from the array. How do I extract the information?(An example of a cell: 22-Jul-2017)

import scipy.io as sio
# create string value to mat file
matPath = 'data/2017_Pervious11_F5.mat'
# load the information in the file in a format that python can interpret
matfile = sio.loadmat(matPath)
# in order: for slab1 get date_time, rn, qh,qe,qg and sup
s1_dates = matfile['S1']['D']

Output:

s1_dates [ MatlabOpaque([ (b'', b'MCOS', b'datetime', array([[3707764736],[         2], [         1], [         1], [        12],[         2]], dtype=uint32))], dtype=[('s0', 'O'), ('s1', 'O'), ('s2', 'O'), ('arr', 'O')])]
like image 934
Matthew Anderson Avatar asked Nov 08 '22 14:11

Matthew Anderson


1 Answers

One solution that worked for me was to convert all matrix entries to 'char' format (in MATLAB), and load the new .mat file using the 'scipy.io.loadmat'.

like image 75
Ellie Avatar answered Nov 14 '22 22:11

Ellie