readtable command for csv file

Hi,
I am having an issue while reading the csv file into MATLAB. The size of the csv file is greater than 100000KB. When I try to read it through the readtable command in MATLAB, it starts skipping some rows in the csv file and gives the following error
Error using readtable (line 223)
Reading failed at line 15473. All lines of a text file must have the same number of
delimiters. Line 15473 has 1 delimiters, while preceding lines have 515.
Note: readtable detected the following parameters:
'Delimiter', ',', 'ReadVariableNames', false, 'Format',

回答 (3 件)

Cris LaPierre
Cris LaPierre 2021 年 2 月 12 日

0 投票

Without seeing what lines 15473 looks like compared to, say, line 1, it's really hard to add to what the error message is already telling you. It would appear the format of your data changes.
You could try looking into some of the options in detectImportOptions. Perhaps "MissingRule","omitRow"? Or "ImportErrorRule","omitRow"?
Waqas Siddique
Waqas Siddique 2021 年 2 月 12 日

0 投票

Line 1 is a row with data enteries in each column. Line 15473 has become a blank row and the corresponding data enteries have moved to the next line which is 15474.

7 件のコメント

Waqas Siddique
Waqas Siddique 2021 年 2 月 12 日
Same issue is happening with some other rows also.
Walter Roberson
Walter Roberson 2021 年 2 月 12 日
Do you mean that the file itself has changed, or are you referring to the output you see with readtable() ?
Waqas Siddique
Waqas Siddique 2021 年 2 月 12 日
Yes the csv file itself has changed and the MATLAB also outpits the above error
dpb
dpb 2021 年 2 月 12 日
編集済み: dpb 2021 年 2 月 12 日
The problem is in the file, not MATLAB; you're blaming readtable for something not its fault nor in its control
As the error message said at the very top --
Error using readtable (line 223)
Reading failed at line 15473. All lines of a text file must have the same number of
delimiters. Line 15473 has 1 delimiters, while preceding lines have 515.
The file was written with a different format at that point; you will have to either fix that or read the file in pieces or somehow work around the badly-formatted file.
Waqas Siddique
Waqas Siddique 2021 年 2 月 12 日
What command can I use to read an excel workbook(xlsx) file as a table into MATLAB?
Walter Roberson
Walter Roberson 2021 年 2 月 12 日
See Cris's suggestion to use import options to see the error handling.
dpb
dpb 2021 年 2 月 12 日

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

Jeremy Hughes
Jeremy Hughes 2021 年 2 月 12 日

0 投票

Try this,
opts = detectImportOptions(filename)
T = readtable(filename,opts)
I think the import options based default reading behavior will work for you. (R2016b or later)
If you're in a MATLAB earlier than R2016b readtable won't be able to handle this file. You will need to read line by line, and parse each line separately.

質問済み:

2021 年 2 月 12 日

回答済み:

2021 年 2 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by