batch reading of xls files
8 ビュー (過去 30 日間)
古いコメントを表示
Hi, I have a couple of xls files with different dimension each. I would like to read them into Matlab for further processing. The code I wrote:
files = dir('*.xls'); %list of xls files n = length(files); %number of files
for i=1:1:n [data txt row] = xlsread(files(i).name);
...here needs to be the 3 dimensional matrix where the 'data' from all files will be put to the next patch end
My problem is how create the 3 dimensions array without specifying the dimension for each batch? is that possible?
As a result I would like to get all my data in one file as 3 dimension array.
Thank you in advance for all the clues.
0 件のコメント
回答 (1 件)
Matt Tearle
2012 年 4 月 2 日
Any array in MATLAB must have consistent dimensions, so if you really want a 3-D array of numbers (doubles), you would have to pad with something -- NaN for example. This can be done, but is not pretty.
So the question is: do you really need a 3-D array, or is that just how you were assuming you'd have to arrange multiple matrices?
Either way, you may want to consider reading the data into a cell array:
n = length(files);
alldata = cell(1,n);
for i=1:1:n
[data txt row] = xlsread(files(i).name);
alldata{i} = data;
end
Now you can access individual arrays using cell indexing:
foo = mean(alldata{3}(:,2)) % average of the 2nd column from the 3rd file
If you really do need a 3-D array of doubles, padded with NaN, you could figure out the dimensions of the largest data, make an array of the appropriate size, and fill it in with the data from alldata.
参考
カテゴリ
Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!