[英]Reading Matlab data in python with scipy.io
我正在尝试使用scipy.io从MATLAB 5.0文件中读取一些实验条件。 问题在于输出文件是一系列极其复杂的数组。 如何过滤matlab文件中的数据?
import scipy.io as sio
with open("sequence_output.txt", "w") as f:
mat = sio.loadmat("seq_data.seq")
f.write(str(mat))
这在输出文件中给了我类似下面的内容。 (实际文件为> 800行)。
如何从该文件中选择所需的数据?
{'__header__': b'MATLAB 5.0 MAT-file, Platform: PCWIN, Created on: Thu Mar 15 13:50:48 2018', '__version__': '1.0', '__globals__': [], 'StepData': array([[(array([[1]], dtype=uint8), array(['LoadPlate'], dtype='<U9'), array([[1]], dtype=uint8), array([[1]], dtype=uint8), array([[0]], dtype=uint8), array([[0]], dtype=uint8), array([[(array([[12]], dtype=uint8), array([[8]], dtype=uint8), array([[0]], dtype=uint8), array([[1]], dtype=uint8), array([[60]], dtype=uint8), array([[1]], dtype=uint8), array([[1]], dtype=uint8), array([[(array([[1]], dtype=uint8), array([[0]], dtype=uint8)),
(array([[1]], dtype=uint8), array([[0]], dtype=uint8)),
(array([[1]], dtype=uint8), array([[0]], dtype=uint8)),
(array([[1]], dtype=uint8), array([[0]], dtype=uint8)),
(array([[1]], dtype=uint8), array([[0]], dtype=uint8)),
(array([[1]], dtype=uint8), array([[0]], dtype=uint8)),
(array([[1]], dtype=uint8), array([[0]], dtype=uint8)),
(array([[1]], dtype=uint8), array([[0]], dtype=uint8)),
(array([[0]], dtype=uint8), array([[0]], dtype=uint8)),
(array([[0]], dtype=uint8), array([[0]], dtype=uint8)),
(array([[0]], dtype=uint8), array([[0]], dtype=uint8)),
(array([[0]], dtype=uint8), array([[0]], dtype=uint8)),
(array([[0]], dtype=uint8), array([[0]], dtype=uint8)),
(array([[0]], dtype=uint8), array([[0]], dtype=uint8)),
mat['StepData']
似乎是一个2d数组,包含一个字符串dtype数组和一整堆uint8
数组(全部为(1,1)数组)。 该数组的shape
可能是(1,n),但显示不完整。 dtype
是object
因为它包含数组作为元素。 MATLAB源可能是一个cell
。
我无法复制-粘贴您的注释来进一步解密它,但是它看起来也像是字符串数组和uint8
的混合。
MATLAB矩阵以numpy数字或字符串数组的形式加载。 它们将始终为2d(或更高),并且可以进行转置(或order ='F')。
MATLAB单元可以包含多种内容(数字,字符串等),并作为对象dtype数组加载。
MATLAB struct作为结构化数组加载,其字段名称与struct字段/属性相对应。
搜索“ [scipy] loadmat”以查看有关使用loadmat
其他问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.