using cat for a sequence of files

suppose that I have some excel files(more than 2, actually 12). How can i use the command ' cat ' in a loop? I want to place one excel file below the other
I am looking something like:
clear all;
fname = {'dataoutput1.xlsx','dataoutput2.xlsx','dataoutput3.xlsx','dataoutput4.xlsx'};
for i=1:length(fname)
a = xlsread(fname{i})
lo=cat(length(fname), a(i,:))
end
Does it matter if the files have different dimensions?
thank

 採用された回答

Andrei Bobrov
Andrei Bobrov 2012 年 5 月 29 日

0 投票

about function cat
fname = {'dataoutput1.xlsx','dataoutput2.xlsx','dataoutput3.xlsx','dataoutput4.xlsx'};
a = cellfun(@xlsread,fname,'un',0);
[m,n] = cellfun(@size,a);
mm = max(m);
mn = max(n);
out1 = arrayfun(@(x,y,z)[x{:},nan(y,mn-z)],a,m,n,'un',0);
out1 = cat(1,out1{:});
out2 = arrayfun(@(x,y,z)[x{:};nan(mm-y,z)],a,m,n,'un',0);
out2 = cat(2,out2{:});

3 件のコメント

antonet
antonet 2012 年 5 月 29 日
thanks it works fine.
the problem though is that the excel files contain sting variales as well. These variable appear as NaN in the out1 ot out2. Is it possible to avoid having this problem?
thanks
Oleg Komarov
Oleg Komarov 2012 年 5 月 29 日
[data,text,all] = xlsread()
Check out the third output of xlsread.
antonet
antonet 2012 年 5 月 30 日
thank you oleg

サインインしてコメントする。

その他の回答 (0 件)

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by