Loading multiple (e.g. ~ 3000) mat files into workspace and merging them in a table
1 次查看(过去 30 天)
显示 更早的评论
I have many mat files (no particular sequence such as file1.mat, file2.mat etc etc) in a folder. I want to load all of them into a workspace and then merge all the mat files in a table.
Any efficient way to do so other than loading all of them manually (which can be done if I select all the files using CTRL+A then press enter, no issues of RAM as I have 16 gigs and the files will take at best 3 gigs of RAM) and then using the table(names of variables,..........)? My main issue is i will need to list all 3000 variables from workspace to table function manually which I don't want to do.
0 个评论
采纳的回答
Stephen23
2019-6-5
编辑:Stephen23
2019-6-5
" i will need to list all 3000 variables from workspace.."
That is a good example of why load-ing directly into the workspace is a bad way to write code.
Preallocate a table (exactly how depends on how you want to join the tables).
Loop over the files. Load each file into a structure, i.e.:
S = load(...)
T = struct2table(S);
Use one of the table join functions to add the new table to the preallocated table:
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!