limited csvread troubled by NAN not within limits

1 回表示 (過去 30 日間)
Juri Maibaum
Juri Maibaum 2018 年 4 月 20 日
編集済み: Juri Maibaum 2018 年 4 月 20 日
When reading csvfiles (~1,000,000x7) that contain several rows and columns, I want to read in only two columns.
data = csvread(filename,3,1,[3 1 1000006 2]);
I cut of the header, so I only have numeric fields. I cut of the rest of the columns except the second and third, so I don't include the corrupted data that contains non-numeric fields ("∞\n"). Despite not including column seven I get:
"Mismatch between file and format character vector.
Trouble reading 'Numeric' field from file (row number 521343, field number 7) ==> ∞\n"
How do I prevent this error?

採用された回答

Walter Roberson
Walter Roberson 2018 年 4 月 20 日
You cannot prevent that problem as long as you use csvread. csvread permits text only in skipped row headers or skipped leading column headers. Everything else must be numeric. The code works by reading everything except the skipped header and skipped column header, and then it throws away the parts outside the range.
You will need to use textscan yourself, or xlsread (if you are using Windows and have excel installed) or readtable
  1 件のコメント
Juri Maibaum
Juri Maibaum 2018 年 4 月 20 日
編集済み: Juri Maibaum 2018 年 4 月 20 日
Thank you for this information. I didn't know about this.
I will now try as suggested and give information and choose the quickest way.
EDIT: using fopen and textscan showed a ten times better performance than using readtable (an other conversion from strings to double was needed) and a roughly 20% better performance than xlsread.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by