concatenating several mat file into one

14 次查看(过去 30 天)
Hi,
I have several mat file like: first.mat ,second.mat ,third.mat,...
all of these files have the same content like: variable1<3400x1 double> , variable2<1143x1 double> , variable3<1141x1 double> , ...
all mat files have the same content but the size of each variable in each mat file is different. I need to concatenate all same variables in all mat files in order to have just one mat file.
can somebody tell me what can I do?which function should I use?
Many thanks.

采纳的回答

dpb
dpb 2014-4-13
Presuming by "math" files you mean a Matlab .mat file,
d=dir('*.mat'); % get the list of files
x=[]; % start w/ an empty array
for i=1:length(d)
x=[x; load(d(i).name)]; % read/concatenate into x
end
save('newfile.mat',x)
  1 个评论
Navid
Navid 2014-4-14
Many thanks for your help.As a beginner your hint gave me the idea, I added some line and now it's working.
clear
PathName = uigetdir;
file_all = dir(fullfile(PathName,'*.mat'));
matfile = file_all([file_all.isdir] == 0);
clear file_all PathName
%d=dir('*.mat'); % get the list of files
x=[]; % start w/ an empty array
for i=1:length(matfile)
x=[x; load(matfile(i).name)]; % read/concatenate into x
end
b=[];
for j=1:length(x)
b=[b; x(j, 1).variable1];
end
FileName = [matfile(i,1).name(1:end-9),'.mat'];
save(FileName,'matfile','x','b');

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Cell Arrays 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by