reading Excel data from Matlab, slow process

20 visualizzazioni (ultimi 30 giorni)
S
S il 17 Nov 2011
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:-)

Risposta accettata

Jan
Jan il 17 Nov 2011
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.

Più risposte (1)

Steven
Steven il 18 Nov 2011
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 Commenti
S
S il 18 Nov 2011
Thanks Steve!
Steven
Steven il 21 Nov 2011
I'm changing all my m files as well.. one that used to run for 2 weeks now does the same job in 8hrs.

Accedi per commentare.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by