2010-03-18 43 views
1

有沒有一種簡單的方法來總結matlab中的各種excel文件? 我真正想要的是類似總結了matlab中的excel文件

DOS命令

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.

感謝

+0

而不是總結,我相信你正在尋找的詞是concatinating。 初看,我以爲你想實際總結一個電子表格的值 – Fuzz 2010-03-18 22:50:32

回答

1

獲取文件名

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

第一個文件。這會在您每次運行此程序時覆蓋輸出 - 如果這是您想要的行爲,則取決於您。

copyfile(names{1},output); 

循環通過文件

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 

這應該工作,如果(1)你只有數字數據和(2)要連接(「總和」,因爲你把它)的文件從上到下。

如果(1)有誤,請閱讀xlsread的幫助 - 尋找txtraw輸出。

+0

不起作用,說文件名應該是字符串 – 2010-03-19 01:53:16

+0

至少有一個錯誤:它應該是名稱{i} – Jonas 2010-03-19 01:59:48

+0

@AP:抱歉,修復; @Jonas:謝謝!我無法運行這個檢查... – AVB 2010-03-19 02:08:57

0

使用xlswrite(filename, M, range)寫你的文件一個接一個。用xlsread將Excel文件讀入M

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

+0

你可以使用uigetfile來讓用戶選擇他們想要連接在一起的文件,然後使用xlsread和xlswrite將它們讀入到matlab中,並寫入它們再出來 – Fuzz 2010-03-18 22:51:48