MATLAB: How to import data files to column vectors in a loop

importing excel data

Hello,
I'm trying to import some data from different .xlsx files into column vectors in Matlab. All files look the same, only the values are different.
Right now Matlab only shows me one vector of each (A,B,C,D,..). I need to have the vectors A,B,C,.. for all files that I read. For example A1,A2,A3,B1,B2,B3,…
Can anyone help me?
Thanks in advance!
———————————
In the code below I make use of a Matlab generated code to import the file into a column vector.
numFiles = 3;
range = 'A1:G100';
sheet = 1;
for fileNum = 1:numFiles
fileName = sprintf('document%1d.xlsx',fileNum);
[A,B,C,D,E,F,G] = importfile(fileName,sheet,range);
end

Best Answer

I don't know your importfile function, but in general you can do it the following way:
for fileNum = 1:numFiles
fileName = sprintf('document%1d.xlsx',fileNum);
[A(:,fileNum),B(:,fileNum),C(:,fileNum),D(:,fileNum),E(:,fileNum),F(:,fileNum),G(:,fileNum)] = importfile(fileName,sheet,range);
end