Multiple 'EndOfLine' readtable

9 ビュー (過去 30 日間)
Mjan88
Mjan88 2019 年 9 月 17 日
コメント済み: Mjan88 2019 年 9 月 18 日
Hi all,
Does anybody know how to impose multiple 'EndOfLine' characters in 'readtable'.
My problem is namely that I'm trying to easily read a csv file (I like the readtable option), in which some lines end with a comma, and other don't.
Read table otherwise gives the error "Line 10 has 29 delimiters, while preceding lines have 28"
Thanks in advance.

回答 (1 件)

Guillaume
Guillaume 2019 年 9 月 17 日
編集済み: Guillaume 2019 年 9 月 17 日
This has nothing to do with the EndOfLine character (which is typically not rendered when viewed in a text viewer).
As the error message tells you, the problem is with the number of delimiters. You can't do anything about that directly with readtable but you could construct a delimitedTextImportOptions object to use with readtable that should be able to cope with this.
Assuming that your file has a header line with the correct number of delimiters, the following would most likely work:
opts = detectImportOptions(yourfile);
opts.ExtraColumnsRule = 'ignore'; %ignore extra columns created by extra delimiters at the end of lines
data = readtable(yourfile, opts)
If it doesn't work, you may need to give more hints to the option object.
  1 件のコメント
Mjan88
Mjan88 2019 年 9 月 18 日
That is a very convenient solution. Thanks a lot

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by