reading Excel data from Matlab, slow process

조회 수: 19 (최근 30일)
S
S 2011년 11월 17일
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:-)
  댓글 수: 1
Jan
Jan 2011년 11월 17일
Please do not post a question twice.

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
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
S
S 2011년 11월 18일
Thank you very much for your help.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Steven
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
S
S 2011년 11월 18일
Thanks Steve!
Steven
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 CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by