MATLAB: Summing numerical data of excel files in Matlab

excel

Hi to all matlab geniuses! I am new in matlab, hope somebody can help me. The question is following: I have 100 excel files with numerical data. I need to sum up relative columns of each file, thus creating a new excel file. Example: My 1st excel file content:
name1 10
name2 20
name3 30
name4 40
name5 50
Second excel file content:
name1 50
name2 40
name3 30
name4 20
name5 10
and other 98 are the same format..
So, I need final excel file like this:
name1 60
name2 60
name3 60
name4 60
name5 60
How to make it in Matlab??? Thank you very much in advance!!

Best Answer

Assuming file names to be coded as follows: data_001.xlsx, data_002.xlsx, .., data_100.xlsx, you could build a solution based on the following approach
nFiles = 100 ;
for fId = 1 : nFiles
filename = sprintf( 'data_%03d.xlsx', fId ) ;
num = xlsread( filename ) ;
if fId == 1
buffer = num ; % See note 1.

else
buffer = buffer + num ; % See note 1.
end
end
Note 1: this assumes that there is only one column of numeric values in the file. If there are multiple, you have to select the relevant column, e.g. if it's column 3: buffer=num(:,3) and buffer=buffer+num(:,3).
This approach can be extended a little with code for e.g. taking all files from a specific folder, or matching names if they can be stored in various orders.