Number of .mat files into single .mat file

조회 수: 2 (최근 30일)
Kishore
Kishore 2022년 8월 9일
댓글: Walter Roberson 2022년 8월 16일
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
Kishore
Kishore 2022년 8월 9일
편집: Kishore 2022년 8월 9일
Sorry, All 10 .mat files variables having same names in the files. Now, I want to overlap all 10 files into a single .mat file.
Matt J
Matt J 2022년 8월 9일
@Kishore If they contain the same variable names, what does it mean to "overlap" all 10 files? A single .mat file cannot contain 2 variables with the same name.

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2022년 8월 9일
편집: Matt J 2022년 8월 9일
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
Matt J
Matt J 2022년 8월 16일
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
Walter Roberson 2022년 8월 16일
Please show the output of
whos -file Data1.mat
whos -file Data2.mat

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Stephen23
Stephen23 2022년 8월 16일
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
ans = 3×3
1 2 3 4 5 6 7 8 9

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by