1
votes

Is there a easy good way to sum up various excel files in matlab? what i really want is similar to

dos command

type file*.xls> sumfile.xls
I have from 10-100 excel files with similar file name formats excet the date XXXXX_2010_03_03.xls, XXXXX_2010_03_03.xls and so on.....
Is there a command to copy the files one after other. All files are of diff length so i cannot know the position of the rows after each file. I would like to have them copied in same sheet of excel.

Thanks

2
rather than summing, I believe the word you are looking for is concatinating. At first look I thought you want to actually sum the values of a spreadsheet - Fuzz

2 Answers

1
votes

Get file names

names=dir('XXXXX-*.xls');
names={names.name};
output='out.xls';

First file. This will overwrite the output each time you run this program - it's up to you if this is the behavior you want.

copyfile(names{1},output);

Cycle through the files

for i=2:length(names)
  num_in = xlsread(names{i}); % read the data
  num_out = xlsread(output);      

  range=['A' num2str(size(num_out,1)+1)]; % next free line 
  xlswrite(output, num_in, 1, range); %always write to the 1st sheet
end

This should work if (1) you only have numerical data and (2) you want to concatenate ("sum", as you put it) the files top to bottom.

If (1) is wrong, please read xlsread's help -- look for txt and raw outputs.

0
votes

Use xlswrite(filename, M, range) to write your files one after the other. Read the Excel file into M with xlsread.

xlswrite(filename, M, range) writes matrix M to a rectangular region specified by range in the first worksheet of the file filename.