Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
read matlab data
#1
Photo 
Hello,
I have some data stored in a matab file (data.mat). The data is stored in a table as shown in the following figure (screen shot from matlab).
   
I use the following python code to read in the mat-file:
import scipy.io as spio
lib = spio.loadmat('data.mat')
lib
Output:
{'__header__': b'MATLAB 5.0 MAT-file, Platform: PCWIN64, Created on: Fri Oct 6 18:07:57 2023', '__version__': '1.0', '__globals__': [], 'None': MatlabOpaque([(b'data_test', b'MCOS', b'table', array([[3707764736], [ 2], [ 1], [ 1], [ 1], [ 2]], dtype=uint32)) ], dtype=[('s0', 'O'), ('s1', 'O'), ('s2', 'O'), ('arr', 'O')]), '__function_workspace__': array([[ 0, 1, 73, ..., 0, 0, 0]], dtype=uint8)}
data_1=lib['__function_workspace__'][0]
data_1
Output:
array([ 0, 1, 73, ..., 0, 0, 0], dtype=uint8)
len(data_1)
Output:
16056
When I read in the mat-file, I get a single vector, which makes no sense to me. Does anyone have an example of how to read in matlab files? I have attached table in the zip-file.

The mat-file is stored with Matlab version 9.7.0.1190202 (R2019b)

Attached Files

.zip   data.zip (Size: 38.14 KB / Downloads: 4)
Reply
#2
Some advice,i not to familiar with read Matlab file into Python.
Quote:To extract meaningful data from the MatlabOpaque object (table), you'd typically have a few options:

Using MATLAB: You can load the .mat file in MATLAB, convert the table to a simpler data structure (e.g., a matrix or an array),
and save it again as a new .mat file.
Then, you can load this new file in Python, and it should be more accessible.

Third-party Tools: There are some Python packages and tools developed by the community that try to handle MatlabOpaque objects.
One such tool is mat4py. You can try using it to see if it decodes your specific .mat file better.

Octave: Although Octave can handle .mat files, it might not handle the newer MATLAB OOP-style objects perfectly.
However, it's worth a try if MATLAB isn't accessible.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Smile How to further boost the data read write speed using pandas tjk9501 1 1,276 Nov-14-2022, 01:46 PM
Last Post: jefsummers
  Read json array data by pandas vipinct 0 1,962 Apr-13-2020, 02:24 PM
Last Post: vipinct
  Python read Excel cell data validation anantpatil 0 4,179 Jan-31-2020, 04:57 PM
Last Post: anantpatil
  Read data, recognize trends and send report vin0001 1 2,143 Oct-02-2019, 06:08 AM
Last Post: buran
  Read CSV data into Pandas DataSet From Variable? Oliver 7 13,991 Jul-05-2018, 03:29 AM
Last Post: answerquest
  Read Data with multiprocessing RomanRettich 1 2,464 Jun-16-2018, 02:33 AM
Last Post: woooee
  Saving data into .mat (Matlab Fiile) Tulo_Stone 0 2,399 Feb-28-2018, 12:57 AM
Last Post: Tulo_Stone
  Need help in framing data read from wav file Vishweshkumar 1 3,689 Feb-10-2017, 01:45 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

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