How to optimalize a xlsread routine?

1 view (last 30 days)
Dear All,
Please consider the code I have written here below. I am a Matlab novice and I was wondering how much faster I could make my program as it takes a fair amount of time for an unfair amount of data.
code:
% In this program we effectively read all xlsx files of a certain folder
% We change pathname in order to download the files of interest
cd('Z:\My Documents\P. Dirkirch\Input Output\All excel files')
% We save all the files information in an array: fileNames
fileNames = dir('*.xlsx');
% Assign the size of the matrix X, note: we know all excel files bear the same structure
Y = xlsread(fileNames(1).name,2);
X = zeros(size(Y,1)-4,size(Y,2)-4,17,length(fileNames));
% Loop the information in the matrix where X(a,b,c,d) is the element (a,b)
% of sheet c+1 in the dth excel file listed in fileNames
for i = 1:length(fileNames)
for j = 1:17
Y = xlsread(fileNames(i).name,j+1);
X(:,:,j,i) = Y(5:end,5:end);
end
end
Thank you for your help.
Alexis

Accepted Answer

Image Analyst
Image Analyst on 2 Dec 2013
You can't if you continue to use xlsread() since it has to launch and shutdown Excel every time. You need to use ActiveX programming. See my demo attached below in blue text. Run it for a demo of how to create, and how to read in Excel workbooks using ActiveX programming. It might look daunting at first but don't be scared. You're a smart engineer and you can handle it. It's well commented to explain every step of the way. It's something you'll need to learn eventually anyway.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!