Numpy 尝试打印mat(Matlab)文件时matplotlib和pylab的打印错误

Numpy 尝试打印mat(Matlab)文件时matplotlib和pylab的打印错误,numpy,matplotlib,scipy,Numpy,Matplotlib,Scipy,在尝试使用scipy.sio绘制.mat文件(Matlab)时,我需要一些帮助。 不确定我还需要做什么才能绘制数据。我希望读者能理解我贴在下面的内容 我打字如下: 结果= [('**ctrllef**t', (1, 1), 'struct'), ('ctrlright', (1, 1), 'struct'), ('ioleft', (1, 1), 'struct'), ('ioright', (1, 1), 'struct'), ('faultleft', (1, 1), 'struct

在尝试使用scipy.sio绘制.mat文件(Matlab)时,我需要一些帮助。 不确定我还需要做什么才能绘制数据。我希望读者能理解我贴在下面的内容

我打字如下: 结果=

[('**ctrllef**t', (1, 1), 'struct'),
 ('ctrlright', (1, 1), 'struct'),
 ('ioleft', (1, 1), 'struct'),
 ('ioright', (1, 1), 'struct'),
 ('faultleft', (1, 1), 'struct'),
 ('faultright', (1, 1), 'struct'),
 ('validleft', (1, 1), 'struct'),
 ('validright', (1, 1), 'struct'),
 ('ovdleft', (1, 1), 'struct'),
 ('ovdright', (1, 1), 'struct')]

mat_a = mat_contents['**ctrlleft**']

import numpy as np

import matplotlib.pyplot as pp

pp.plot(mat_a, mat_contents, 'x')

**Result =**  ValueError: Can't cast from structure to non-structure, except if the structure only has a single field

from pylab import *

from matplotlib import *

matshow(mat_a)
Result=
类型错误:基于
(“**ctrllef**t',(1,1),“struct')
我认为
mat_a
是一个(1,1)对象数据类型数组,无法将图像数据转换为float
mat_a.item()
可能是一个结构化数组,MATLAB
struct
对象的每个属性都有一个字段。这种数组的字段是按名称访问的

通常我只是在
ipython
上显示(打印)
mat_内容
,或者如果太大,显示
mat_.item()
mat_a.item().dtype
和它的
.shape
一样也是一个有用的显示

您需要以某种方式沿着
loadmat
生成的数据结构向下移动,直到获得可以传递到
plot
ndarray
。如果不了解更多关于MATLAB数据结构的知识,我无法预测
mat\u内容是什么样的。即使这样,我发现在
numpy
会话中以交互方式探索该对象更容易

loadmat
产生的对象类型已在前面的许多SO问题中讨论过。由于MATLAB源代码不同,我们只能给出一般性的指导

最近一个将MATLAB
struct
传递到
numpy
的例子:


当我键入'mat_a.item().dtype'时,收到的错误消息是AttributeError:'tuple'对象没有属性'dtype'。你能解释一下你所说的“你需要沿着loadmat生成的数据结构往下走,直到你得到可以传递到绘图的数据集”是什么意思吗?谢谢你花时间回复hpaulj。那么你打算让我猜一下
元组的内容是什么。你有文件和数据,我没有。我只能根据过去使用
mat
文件等问题的经验进行猜测。MATLAB结构和
numpy
结构之间没有一对一的匹配。我只是在学习python。。但这就是我得到的。我希望这就是你要找的。np.where(mat_a)Out[26]:(array([0],dtype=int64),array([0],dtype=int64)),如果您进入MATLAB并保存一个新文件,其中只包含一些要绘制的矩阵,可能会更简单。矩阵和numpy数组之间的匹配更简单。我将尝试您的建议。再次感谢你的帮助。
[('**ctrllef**t', (1, 1), 'struct'),
 ('ctrlright', (1, 1), 'struct'),
 ('ioleft', (1, 1), 'struct'),
 ('ioright', (1, 1), 'struct'),
 ('faultleft', (1, 1), 'struct'),
 ('faultright', (1, 1), 'struct'),
 ('validleft', (1, 1), 'struct'),
 ('validright', (1, 1), 'struct'),
 ('ovdleft', (1, 1), 'struct'),
 ('ovdright', (1, 1), 'struct')]

mat_a = mat_contents['**ctrlleft**']

import numpy as np

import matplotlib.pyplot as pp

pp.plot(mat_a, mat_contents, 'x')

**Result =**  ValueError: Can't cast from structure to non-structure, except if the structure only has a single field

from pylab import *

from matplotlib import *

matshow(mat_a)