How do I combine multiple MAT files into a single matrix
23 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I'm running a script currently that analyses multiple c3d files and outputs al the variables im interested in as a single array (1 row x N columns).
So I end up with multiple saved flies let say for example A.mat, B.mat, C.mat. all containing the same array layout but with different values, but they will all have the same Variable Name in the workspace.
What I want to do is combine files A, B, and C into one Matrix so that as I load a new .Mat file it will populate underneath the previous row of data.
Any suggestions?
Sorry I'm a bit of a rookie when it comes to Mablab
0 件のコメント
回答 (3 件)
Stephen23
2017 年 4 月 12 日
編集済み: Stephen23
2017 年 4 月 12 日
Easy: load into a variable (which is a structure):
S = load(...);
Do this in a loop, and construct a non-scalar structure containing all of the mat files' data. Here are some examples:
Once you have the data in the structure it is easy to access or combine together into one array.
0 件のコメント
Jan
2017 年 4 月 12 日
Try something like this:
FileList = dir('*.mat');
DataC = cell(1, numel(FileList));
for iFile = 1:numel(FileList);
FileData = load(FileList(iFile).name);
DataC{iFile} = FileData.YourVar;
end
DataM = cat(1, DataC{:}); % Or the 2nd or 3rd dimension?!
This imports all files, stores the wanted data in a cell and creates a matrix finally.
0 件のコメント
Sean Byrne
2017 年 4 月 13 日
参考
カテゴリ
Help Center および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!