- Text files, only these parameter names apply: FileType, ReadVariableNames, ReadRowNames, TreatAsEmpty, DatetimeType, Delimiter, HeaderLines, Format, EmptyValue, MultipleDelimsAsOne, CollectOutput, CommentStyle, ExpChars, EndOfLine, DateLocale, and Encoding.
- Spreadsheet files, only these parameter names apply: FileType, ReadVariableNames, ReadRowNames, TreatAsEmpty, DatetimeType, Sheet, Range, Basic, and TextType.
- Text or Spreadsheet files with the opts import options, only these parameter names apply: ReadVariableNames, ReadRowNames, DateLocale, Encoding, Sheet, and Basic. "
Why doesn't 'HeaderLines' work in the readtable command?
171 views (last 30 days)
I am importing some excel files into Matlab using the readtable command. There are a couple of header lines in the file that I would like to skip, but when I use the name-value pair ('HeaderLines',2), I get an error:
Error using readtable (line 198)
Invalid parameter name: HeaderLines.
Has anyone else experienced this? Is there a way to get around this error?
Walter Roberson on 31 Mar 2018
You are reading a spreadsheet file. You need to use Range instead of HeaderLines
More Answers (1)
Bradley Stiritz on 21 Oct 2018
Edited: Bradley Stiritz on 25 Apr 2019
Walter's solution is a good one, when the number of table rows are known in advance. In my case, I have Excel files with a fixed number of header rows, and variable number of data rows.
I reached out to tech support, and got the following solution. This works well for me, I hope it can help others also--
% Assume Excel file has 6 header rows
>>path_ = 'C:\data\my_file.xlsx';
>>ImportOptions_ = detectImportOptions(path_, 'NumHeaderLines', 6);
>>tb = readtable(path_,ImportOptions_);
(Edit: corrected minor bugs per Doug Bergman)