Preallocation not helping with speed; actxserver
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Robert Dylans
el 1 de Sept. de 2015
Comentada: Robert Dylans
el 2 de Sept. de 2015
I have a folder of 500 separate Excel files (.csv to be specific). I'm reading a specific data range from them. My main problem is that it's taking longer than I would expect. Originally with xlsread I was taking ~200 seconds. I've recently learned of using actxserver and have cut down to ~50 seconds. I'm trying to preallocate memory for it, but I've noticed that the duration is exactly the same whether I do this or not.
z=zeros(3452,1);
for i=1:500
high{i}=z;
end
tic
folder='F:\Program Files\Historical\daily';
files=dir(fullfile(folder,'*.csv'));
e=actxserver('Excel.Application');
for k=1:numel(files)
waitbar(k/numel(files),progress);
ExcelWorkbook=e.workbooks.Open(fullfile(folder,files(k).name));
range=ExcelWorkbook.ActiveSheet.Range('E1:E3452');
high{k}=range.Value;
end
toc
Am I formatting the preallocation wrong? Or am I missing something else? Or is my computer just slow?
Thanks for any help.
0 comentarios
Respuesta aceptada
Image Analyst
el 1 de Sept. de 2015
They're simple csv files, not complicated workbooks. Have you tried simply using csvread()? Maybe that will be faster since there's no overhead of trying to launch and shutdown Excel.
1 comentario
Más respuestas (0)
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!