6

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')])]
3
  • 1
    Provide MATLAB code to generate the exact file you are trying to open. Commented Nov 8, 2017 at 6:17
  • 1
    Looking up MatlabOpaque, it looks like the mat file contains some MATLAB class/object that loadmat cannot translate into numpy. Dates, unless given in some consistent string format, are not readily interchangeable across programming languages. I wouldn't expect a Python datetime object to be usable in MATLAB. Commented Nov 8, 2017 at 7:17
  • 1
    here is the link to the mat file drive.google.com/open?id=0B_s-ZK-B0ITFTU5mS1UyblhuRkE Commented Nov 9, 2017 at 5:12

1 Answer 1

0

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'.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.