自动加载多个 *.mat 文件和矩阵调整大小
我有大量的实验室工作数据需要处理。我有大量 .mat 文件,其中包含尺寸为 7 x w 的信号矩阵。我需要将矩阵大小调整为 7 x N,并且 w 比 N 更大和更小,以使其余分析更容易(不关心超过 N 的数据)。我有我希望它如何工作的伪代码,但不知道如何实现它。任何帮助将非常感谢!
我所有数据的文件夹结构:
主文件夹
Alpha 1
1111.mat
1321.mat
Alpha 2
1010.mat
1234.mat
1109.mat
933.mat
Alpha 3
1223.mat
等。
伪代码:
Master_matrix = []
For all n *.mat
Load n'th *.mat from alpha 1
If w > N
Resize matrix down to N
Else
Zero pad to N
End if
Master_matrix = master_matrix .+ new resized matrix
End for
rest of my code...
I have a ton of data that needs to be processed from lab work. I have a ton of .mat files that contain a signal matrix of dimensions 7 x w. I need to resize the matrix to 7 x N and w is larger and smaller than N to make the rest of the analysis easier (don't care about data past N). I have the psuedocode of how I want this to work but don’t know how to implement it. Any help would be great thanks!
Folder structure of all my data:
Main folder
Alpha 1
1111.mat
1321.mat
Alpha 2
1010.mat
1234.mat
1109.mat
933.mat
Alpha 3
1223.mat
etc.
Psudeocode:
Master_matrix = []
For all n *.mat
Load n'th *.mat from alpha 1
If w > N
Resize matrix down to N
Else
Zero pad to N
End if
Master_matrix = master_matrix .+ new resized matrix
End for
rest of my code...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先您需要生成文件列表。我有自己的功能,但有,例如 GETFILELIST 或出色的交互式 UIPICKFILES 生成文件列表。
获得文件列表后(我假设它是包含文件名的元胞数组),您可以执行以下操作:
注意:如果您实际上不想添加数据,而只是将其存储在主数组中,您可以将 Master_matrix 制作成 7×N×nFiles 数组,其中 Master_matrix 的第 n 个平面是第 n 个文件的内容。在这种情况下,您可以将
Master_matrix
if 子句编写为
初始化为
NaN
,并将 code> 而不是zeros
,这样零就不会影响后续统计信息(如果您想对数据执行此操作)。First you need to generate the file list. I have my own function for that, but there is, for example, GETFILELIST or the excellent interactive UIPICKFILES to generate the list of files.
Once you have the file list (I'll assume it's a cell array containing the filenames), you can do the following:
Note: In case you don't actually want to add up the data, but simply store it in the master array, you can make
Master_matrix
into a 7-by-N-by-nFiles array, where the nth plane ofMaster_matrix
is the content of the nth file. In this case, you'd initializeMaster_matrix
asand you'd write the if-clause as
Also note that you might want to initialize
Master_matrix
asNaN
instead ofzeros
, so that the zeros don't affect subsequent statistics (if that's what you want to do with the data).