reading Excel data from Matlab, slow process
19 次查看(过去 30 天)
显示 更早的评论
Hi everyone,
Got a question...
I have my data stored as Excel files, I use 'xlread' command to read them, calculate the average, and then write the results again on the same Excel files. I have about 3000 files and each file has 1000 samples. These are the codes for my programme:
clc
clear d
clear all
format long
a=0;
b=0;
c=0;
h=1;
d = zeros(1000, 1);
for count=1:2632
if a==45
a=0;
b=b+1;
end
for cell=11:1010
format bank
d(h,1)=xlsread(['D:\S9_G24' '\X' num2str(a) 'Y'
num2str(b) 'Z' num2str(c) '.xls'],1,['B' num2str(cell)]);
h=h+1;
if h==1001
aver=mean2(d);
xlswrite(['D:\S9_G24' '\X' num2str(a) 'Y'
num2str(b) 'Z' num2str(c) '.xls'],aver,1,'B1012');
a=a+1;
h=1;
end
end
end
Codes are fine, but the time it takes is extremely long. It is killing me as I am a bit in rush to get these results. Should I convert my data to a special format or something? I was wondering if anyone has got a good suggestion to speed up the process. I appreciate your help.
BW,
S:-)
采纳的回答
Jan
2011-11-17
Do not read the input element by element but the complete column at once:
d = xlsread(sprintf('D:\S9_G24\X%dY%dZ%d.xls' a, b, c), ...
1, sprintf('B%d:B%d', 10, 1010))
Some other notes:
- Do not use "cell" as name of a variable, because this overwrites an important Matlab command.
- The repeated application of "format bank" wastes time.
- Your input d is a vector. Then mean is more apropriate than mean2.
更多回答(1 个)
Steven
2011-11-18
To get around the fact that the xlsread & xlswrite commands are very slow you'll need to use ActiveX commands. They aren't complicated at all and are explained very clearly on the following website: http://www.orient-lodge.com/node/3430
2 个评论
Steven
2011-11-21
I'm changing all my m files as well.. one that used to run for 2 weeks now does the same job in 8hrs.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!