Tôi đã tìm thấy 2 cách: scipy hoặc mat4py.
- mat4py
tải dữ liệu từ MAT-file
Chức năng loadmat tải tất cả các biến được lưu trữ trong MAT-file thành một cấu trúc dữ liệu Python đơn giản, chỉ sử dụng dict Python và liệt kê các đối tượng . Các mảng số và ô được chuyển đổi thành các danh sách được xếp theo thứ tự được liệt kê theo hàng . Mảng được ép để loại bỏ mảng chỉ với một phần tử. Cấu trúc dữ liệu kết quả bao gồm các loại đơn giản là tương thích với định dạng JSON.
Ví dụ: Load một MAT-file thành một cấu trúc dữ liệu Python:
data = loadmat('datafile.mat')
Từ:
https://pypi.python.org/pypi/mat4py/0.1.0
- scipy:
Ví dụ:
import numpy as np
from scipy.io import loadmat # this is the SciPy module that loads mat-files
import matplotlib.pyplot as plt
from datetime import datetime, date, time
import pandas as pd
mat = loadmat('measured_data.mat') # load mat-file
mdata = mat['measuredData'] # variable in mat file
mdtype = mdata.dtype # dtypes of structures are "unsized objects"
# * SciPy reads in structures as structured NumPy arrays of dtype object
# * The size of the array is the size of the structure array, not the number
# elements in any particular field. The shape defaults to 2-dimensional.
# * For convenience make a dictionary of the data using the names from dtypes
# * Since the structure has only one element, but is 2-D, index it at [0, 0]
ndata = {n: mdata[n][0, 0] for n in mdtype.names}
# Reconstruct the columns of the data table from just the time series
# Use the number of intervals to test if a field is a column or metadata
columns = [n for n, v in ndata.iteritems() if v.size == ndata['numIntervals']]
# now make a data frame, setting the time stamps as the index
df = pd.DataFrame(np.concatenate([ndata[c] for c in columns], axis=1),
index=[datetime(*ts) for ts in ndata['timestamps']],
columns=columns)
Từ:
http://poquitopicante.blogspot.fr/2014/05/loading-matlab-mat-file-into-pandas.html
- Cuối cùng, bạn có thể sử dụng PyHogs nhưng vẫn sử dụng scipy:
Reading phức tạp .mat
tập tin.
máy tính xách tay này cho thấy một ví dụ về đọc một file .mat Matlab, chuyển đổi dữ liệu vào một cuốn từ điển có thể sử dụng với các vòng, một âm mưu đơn giản của dữ liệu.
http://pyhogs.github.io/reading-mat-files.html
Giải pháp tuyệt vời. Điều này phải được chọn câu trả lời. – Jack