MATLAB: How to merge different dimension .mat files to single file

arraymatrixmergesave

Hii, experts i have 5 number of .mat file having dimension 550×128,550×128,550×128,550×128 & 550×132. I just want to merge them into single .mat file so that single mat file would have dimension 550×644. Additionally, variable name(dn) of all the files are same
i did something like this
new_var=[];
load a.mat
new_var=[new_var;dn]
load b.mat
new_var=[new_var;dn]
load c.mat
new_var=[new_var;dn]
load d.mat
new_var=[new_var;dn]
load e.mat
new_var=[new_var;dn]
save('merged.mat','new_var','-v7.3')
But it doesnot work.I hope experts will help me.Thanks in advance.

Best Answer

A mat file is not the same thing as a variable. You can actually store multiple variables in a single mat file if you want. See here.
If you variables all have the same name, you can use the S = load(___) syntax to load to a structure you define, avoiding overwritting the existing variable.
You need to decide how you want to combine the matrix that is 550x132 with the rest. In order to concatenate it vertically, all must have the same number of columns. Should the extra columns be NaN? Zeros?
A = load('a.mat');
B = load('b.mat')
C = load('c.mat')
D = load('d.mat')
E = load('e.mat')
newVar = [A.dn;B.dn;C.dn;D.dn];
newVar(:,end+1:132) = nan;
newVar = [newVar;E.dn];
save('merged.mat','newVar')