我对Python
非常陌生,我必须对工作中的现有项目进行一些更改。我正在将Matlab
二进制数据文件中的数据导入到我的Python
脚本中。在
假设原始*.m
文件包含如下内容:
> Temperature=61.3
>
> VibrationSamples=[76,75,76,77, ... a lot of samples, 78]
>
> save(filename.mat, 'Temperature', 'VibrationSamples', '-mat7-binary')
(这是我能提供的最简单的例子)
我使用
^{pr2}$之后,我可以使用
> variableA = mat('temperature')
> variableB = mat('vibrationSamples')
但是我对结果感到困惑。如果我尝试打印varialbeA,例如,它将得到二维数组。print variableA
的输出是[[61.3]]
。在*.m
文件中,它显然是float
。在
为什么会这样。什么是干净的解决方法?我知道我可以用
> variableA = mat('temperature')[0][0]
但这看起来并不合适。在
我做错什么了吗?在
这就是MATLAB存储标量的方式。在MATLAB数据模型中,标量用1×1数组表示。在
所以在Python中,您可以像这样提取值:
关于这个问题的MATLAB方面的更多信息可以在这里找到:http://www.mathworks.co.uk/help/matlab/math/empty-matrices-scalars-and-vectors.html#f1-86433
相关问题 更多 >
编程相关推荐