在Python中加载Matlab .mat格式的信号日志导出文件。

huangapple go评论70阅读模式
英文:

Load matlab .mat export of signal logs in python

问题

我正在使用Matlab R2023a导出信号,如下所示:

save logs.mat logsout -v7

v7是推荐的版本,用于在Python中读取文件(在不同的讨论中看到)。

然而,Python读取的文件与我在Matlab中拥有的不同。在Matlab中,我有一个很好的数据集:

在Python中加载Matlab .mat格式的信号日志导出文件。

但在Python中使用以下代码读取后:

from scipy.io import loadmat  # 这是加载mat文件的SciPy模块
mat = loadmat('logs.mat')

我看到的是这样的:

在Python中加载Matlab .mat格式的信号日志导出文件。

与结构不同,我有一个形状为(1, 277355408)的数组。我错过了什么?我需要在生成后在Python中处理这些信号。

英文:

I am exporting signals in matlab R2023a like this:

save logs.mat logsout -v7

v7 is recomended version for reading the file in python (seen in different threads).

However, the file read by python is different from what I have in matlab. In matlab I have a nice dataset:

在Python中加载Matlab .mat格式的信号日志导出文件。

but after reading it in python with following code:

from scipy.io import loadmat  # this is the SciPy module that loads mat-files
mat = loadmat('logs.mat')

this is what I see:

在Python中加载Matlab .mat格式的信号日志导出文件。

Instead of structure, I have a array of shape (1, 277355408). What do I miss? I need to process the signals in python after generating.

答案1

得分: 0

看起来,正如@hpaulj所建议的,loadmat可以处理Matlab的矩阵、单元和结构体。似乎不能处理数据集。我通过像这样单独导出变量来解决了这个问题:

logsout{1}.Values.Data 
save(logsout{1}.Name, 'ans', '-v7')

这只是第一个信号的示例。

现在我可以使用scipy来读取它。然而,还有一种将其保存为hdf5文件并按以下方式读取和处理的方法:

import nexusformat.nexus as nx
f = nx.nxload('logs.h5')
prem = f.tree # 这可以用来打印树

# 或者像这样
import h5py
f = h5py.File('logs.h5', 'r')
英文:

It seems, as suggested by @hpaulj - loadmat can handle matlab matrix, cell, and struct. Looks like it can't handle a dataset. I solved it by exporting variables alone like this:

logsout{1}.Values.Data 
save(logsout{1}.Name, 'ans', '-v7')

Just an example for first signal.

Now I can read it with scipy. However, there is also way to save it as hdf5 file and read and work with it as follows:

import nexusformat.nexus as nx
f = nx.nxload('logs.h5')
prem = f.tree # this can be used to print the tree

#or like this
import h5py
f = h5py.File('logs.h5', 'r') 

huangapple
  • 本文由 发表于 2023年7月12日 20:34:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76670595.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定