MATLAB: Concatenating several mat file into one

concatenate several math file with same contentMATLAB

Hi,
I have several mat file like: first.mat ,second.mat ,third.mat,…
all of these files have the same content like: variable1<3400×1 double> , variable2<1143×1 double> , variable3<1141×1 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.

Best Answer

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)
Related Question