Performance: readTable versus xlsread

조회 수: 128 (최근 30일)
fsgeek 2021년 3월 27일
댓글: Jeremy Hughes 2022년 7월 7일
Dear Community,
I am reading the contents of an Excel Workbook (.xlsx) file. It's a pretty large, but not crazy file (approximately 26k rows-by-24 columns; 3MB). The data is a mixture of a text header (row 1) and the rest is a mixture of numbers and strings.
Until now, I've been using xlsread to process this file. According to the MATLAB documentation, xlsread is not recommended and I should consider readtable or readcell instead:
"The readtable, readmatrix, and readcell functions have these advantages over the xlsread function: Better cross-platform support and performance..."
In MATLAB 2019a for my Excel file, xlsread takes about 1.2 seconds to get the output; readtable takes about 12 seconds; readcell takes about 42 seconds.
It appears to me that xlsread is superior to the other two methods when it comes to speed. Hence my question: What is meant in the documentation by "Better cross-platform support and performance"? What is this performance measured relative to? I appreciate that readtable and readcell have various other advantages, so I understand their use cases. I'm wondering if there's anything obvious that I'm missing which could improve the performance?
I'm calling the methods in a very simple fashion:
[~, ~, csvData] = xlsread(filename);
csvData = readtable(filename);
csvData = readcell(filename);
  댓글 수: 1
Jeremy Hughes
Jeremy Hughes 2022년 7월 7일
Interested if you've tried this is a recent MATLAB release. Or if you have a file that is running slowly, attach it. Then someone might be able to provide a better answer.

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

답변 (1개)

Abdolkarim Mohammadi
Abdolkarim Mohammadi 2021년 3월 28일
편집: Abdolkarim Mohammadi 2021년 3월 28일
I don't know about the exact thing you mentioned, but I have experienced that when reading many matrixes from Excel (hence many calls to xlsread() or readmatrix()), the file with readmatrix() runs significantly faster than the same file but with xlsread().
  댓글 수: 1
fsgeek 2021년 3월 29일
That sounds promising. Unfortunately, I can't use readmatrix because my data contains non-numeric cells.

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


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