is there instead solution of xlsread()?

5 次查看(过去 30 天)
its needed to convert .xls files to .mat but speed of reading by xlsread is too low. is there instead solution of xlsread()? (file exchange or other way to convert .xls to .mat)
UPDATED:
Folder=cd(directory);
d = dir('*.xls');
N_File=numel(d);
e = actxserver ('Excel.Application');
h=waitbar(0,'Progress...');
for o = 1:N_File
qs=numel(d)-o;
clc;
fprintf('Please wait %d second ',qs)
fprintf(1,repmat('\n',1,1));
waitbar(o/N_File,h);
% r = xlsread(d(o).name,2);
cd(directory);
ExcelWorkbook = e.workbooks.Open(fullfile(Folder,d(o).name));
Sheet=ExcelWorkbook.Sheets.Item(2);
Range=Sheet.UsedRange;
r=cell2mat(Range.Value);
ExcelWorkbook.Close;
d=sprintf('r%d',o);
assignin('base',d,r);
end
close all;
e.Quit;
e.delete;
  3 个评论
mohammad
mohammad 2011-9-21
realy nice, i save it in workspace by this command: d=sprintf('r%d',o);
assignin('base',d,r);
that while using this, errors:
??? Improper index matrix reference.
Error in ==> chechspeed at 34
ExcelWorkbook = e.workbooks.Open(fullfile(Folder,d(o).name));
mohammad
mohammad 2011-9-21
wao perfect now it takes 30 seconds (170 seconds saving)
there is no errors
you are really professional in MATLAB
thanks a lot

请先登录,再进行评论。

采纳的回答

Fangjun Jiang
Fangjun Jiang 2011-9-20
Try the COM server running Microsoft Excel.
  12 个评论
Fangjun Jiang
Fangjun Jiang 2011-9-21
For example, don't put the line "e = actxserver ('Excel.Application')" inside the for-loop. Instead, put it outside of the for-loop. Inside the loop, just open the file, read, then close the file. Definitely it is going to be much faster than using xlsread() because every time xlsread() is called, a COM server is created and then deleted.
mohammad
mohammad 2011-9-21
when i put outside the for loop errors this:
??? No appropriate method, property, or field workbooks for class handle.handle.
Error in ==> chechspeed at 34
ExcelWorkbook = e.workbooks.Open(fullfile(pwd,dfile));

请先登录,再进行评论。

更多回答(1 个)

Jan
Jan 2011-9-20
Do you speak of binary Excel files or tab separated ASCII files? While the binary files are imported using an Excel-function, reading ASCII-files can be done faster using a C-Mex. To my surprise FSCANF('%f') of MSVC2008 is slower than a hand-coded C-method to import numbers from ASCII files.
But an implementation of all features of READXLS will consume a lot of time. It will not be a benefit to spend a week for programming to accelerate the data import by some hours only. I have only the core function at the momemt to read from other ASCII files.
Do you import the file from a network drive? Then the speed is most likely limited by the network communication and an acceleration of the reading function would not help very much.
  5 个评论
Jan
Jan 2011-9-21
Please use an external editor, e.g. WordPad. If it shows rubbish, the file is in binary format.
mohammad
mohammad 2011-9-21
OK Jan, I opened by WordPad and it shows rubbish!
so there is no way for more speed?

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by