How to merge data’s of multiple dot mat files in one dot matfile (one table)

Hello every one
I have multiple dot mat files like x0.mat, x1.mat, x2.mat, x3.mat
and each file contains 1D time series data. What I need is to merge those data found in each dot mat file in one dot mat file, which contains the name of the files with corresponding data's. I have attached the dot mat files
Thanks for your help

 Akzeptierte Antwort

Hi,
Here is a simple solution:
for ii=1:4
FN= strcat(['x' num2str(ii-1)], '.mat');
D=load(FN);
X_all(ii,:)=D.x; % OR: % x(ii,:)=D.x;
end
save('ALL.mat', 'X_all') % OR: save('ALL.mat', 'x')
Good luck.

6 Kommentare

Thank you so much for response and for the answer.you did exactly what I need but only the file name is missing, how can i add the the name of file infront of the data in the same row?
% File Names are generated and read here:
FN= strcat(['x' num2str(ii-1)], '.mat');
% You can name the variables and save every individual read data back to
% the same file name as if I understood your question correctly.
Good luck.
Off Corse I have accepted your answer Dear Eshkablove, but if it’s possible please modify the algorithm to get output that look likes table below, inside of 'X_all' .
Thank you somuch for the help
Alread X_all variable contains in this row order of all imported data x0, x1, .. x3.
Here are two table formats from which you can choose whichever works for your assignment.
% In a Column Order
X_ALL = array2table(X_all', 'variablenames', {'x0', 'x1', 'x2', 'x3'});
% In a Row Order
VAR = {'x0'; 'x1'; 'x2'; 'x3'};
X_TABLE = table(VAR, X_all);
Thank you so much this worked prefectlly!!! I got all the information in 'X-Table'
It is just a pleasure! Most Welcome!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by