Why doesn't 'HeaderLines' work in the readtable command?
古いコメントを表示
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?
採用された回答
その他の回答 (1 件)
Bradley Stiritz
2018 年 10 月 21 日
編集済み: Bradley Stiritz
2019 年 4 月 25 日
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)
2 件のコメント
Doug Bergman
2019 年 4 月 25 日
編集済み: Doug Bergman
2019 年 4 月 25 日
Brad, your solution worked well for me, once i realized that
path
is the full filename and not just the directory path, and
IOpts
is the same as
ImportOptions_
Thanks for posting, saved me a day of pulling my hair out.
Bradley Stiritz
2019 年 4 月 25 日
Hi Doug, thank you for your comment and correction notes. I'm glad you were able to save some time. Apologies for the sloppy code example, I have edited my post accordingly.
カテゴリ
ヘルプ センター および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!