将多个.mat文件加载到Matlab工作区 [英] Load Multiple .mat Files to Matlab workspace
问题描述
我正在尝试将几个.mat文件加载到工作区.但是,它们似乎互相覆盖.相反,我希望它们附加.我知道我可以做类似的事情:
I'm trying to load several .mat files to the workspace. However, they seem to overwrite each other. Instead, I want them to append. I am aware that I can do something like:
S=load(file1)
R=load(file2)
等
,然后手动附加变量.
但是有很多变量,并且为每个变量添加一个append语句是非常不可取的(尽管可以作为最后的选择).我有什么方法可以将.mat文件加载到工作区中(通过使用load()
命令而不进行赋值)并将它们附加?
But there's a ton of variables, and making an append statement for each one is extremely undesirable (though possible as a last resort). Is there some way for me to load .mat files to the workspace (by using the load()
command without assignment) and have them append?
推荐答案
目前尚不清楚附加"的含义,但这是一种将数据加载为易于处理的格式的方法:>
Its not entirely clear what you mean by "append" but here's a way to get the data loaded into a format that should be easy to deal with:
file_list = {'file1';'file2';...};
for file = file_list'
loaded.(char(file)) = load(file);
end
这利用动态字段引用将列表中每个文件的内容加载到loaded
结构自己的字段中.您可以从此处遍历字段并处理数据.
This makes use of dynamic field references to load the contents of each file in the list into its own field of the loaded
structure. You can iterate over the fields and manipulate the data however you'd like from here.
这篇关于将多个.mat文件加载到Matlab工作区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!