Number of .mat files into single .mat file
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Kishore
am 9 Aug. 2022
Kommentiert: Walter Roberson
am 16 Aug. 2022
Hi,
I've 10 .mat files. I want to overlap all 10 .mat files into one (single) mat file.
For ex: my filename is data1, data2,......,data10.mat.
Can someone help me to solve this problem???
Thanks in advance
3 Kommentare
Akzeptierte Antwort
Matt J
am 9 Aug. 2022
Bearbeitet: Matt J
am 9 Aug. 2022
It depends what they contain and how you want the variables joined within the final .mat file. One way:
filenames="data"+(1:10)+".mat";
for i=1:numel(filenames)
S(i)=load(filenames(i));
end
save("JoinedData.mat",'S')
9 Kommentare
Matt J
am 16 Aug. 2022
JoinedData.mat matrix value should be like this, 44444 x 67
It won't be. loading JoinedData.mat will give you the structure S, which you already have in the workspace.
Walter Roberson
am 16 Aug. 2022
Please show the output of
whos -file Data1.mat
whos -file Data2.mat
Weitere Antworten (1)
Stephen23
am 16 Aug. 2022
Fake data:
X = 1:3;
save data1.mat X
X = 4:6;
save data2.mat X
X = 7:9;
save data3.mat X
clear
Joining file data:
N = 3;
C = cell(1,N);
for k = 1:N
F = sprintf('data%d.mat',k);
C(k) = struct2cell(load(F));
end
Xnew = vertcat(C{:});
save('joineddata.mat','Xnew')
Checking:
S = load('joineddata.mat');
S.Xnew
0 Kommentare
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!