MATLAB: Doesn’t ‘HeaderLines’ work in the readtable command

importing excel datareadtable

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?

Best Answer

"When reading:
  • 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. "
You are reading a spreadsheet file. You need to use Range instead of HeaderLines