Performance issues with readtable vs. xlsread
15 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am working in R2020a and have converted the Excel file read in one of my MATLAB scripts from xlsread to readtable, since xlsread is now deprecated.
However, I am having performance issues with readtable compared to xlsread.
The Excel file is a 15MB .xlsb file with six sheets, and I am using named ranges to locate the data on the approrpriate sheet.
tic; [perforations, perforations_header] = xlsread(xls_file,sheet,'PERFORATIONS'); toc
Elapsed time is 4.354259 seconds.
tic; T=readtable(xls_file,'Sheet',sheet,'Range','PERFORATIONS'); toc
Elapsed time is 15.777517 seconds.
perforations = table2array(T); perforations_header=T.Properties.VariableNames; toc
Elapsed time is 15.803216 seconds.
So, two questions:
(1) Any suggestions on how to improve performance for readtable?
(2) Despite xlsread being deprecated, it clearly performs better than readtable. Is there any downside with staying with xlsread?
My thanks!
Mike
P.s. Attached is a cut down version of the Excel .xlsb file. It contains two named ranges: 'PERFORATIONS' and 'CELLS'. The full file was too large to attach.
2 Commenti
Walter Roberson
il 3 Dic 2020
Consider experimenting with readtable() with the 'UseExcel', true flag.
Risposta accettata
Star Strider
il 2 Dic 2020
If you need to use xlsread, use it as long as you have it available.
Since you obviously want the header information as well, one option could be to use readtable once to read everything in once (likely using 'VariableNamingRule','preserve' in your call to it), perhaps extracting the variable names separately as <tablename>.Properties.VariableNames to a cell, then using save to put all the information you want in a .mat file. Then load the .mat file as necessary to retrieve the necessary information into your workspace. Either save the headers and data separately as different variables, or save it as a table.
I have no idea how efficient this would be, since I have no idea what your Excel file contains, or how large it is. It is simply an option to consider.
2 Commenti
Star Strider
il 3 Dic 2020
My pleasure!
My idea is to read them in once with readtable, save them to .mat files, then load them as necessary when you need them later.
If a function is deprecated, it will not be supported (and will likely not appear) beginning in some future release, although code using it may still work. (It’s complicated!)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Spreadsheets in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!