How do I combine multiple MAT files into a single matrix
25 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (3)
Stephen23
el 12 de Abr. de 2017
Editada: Stephen23
el 12 de Abr. de 2017
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 comentarios
Jan
el 12 de Abr. de 2017
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 comentarios
Sean Byrne
el 13 de Abr. de 2017
Ver también
Categorías
Más información sobre Structures en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!