Filter löschen
Filter löschen

limited csvread troubled by NAN not within limits

3 Ansichten (letzte 30 Tage)
Juri Maibaum
Juri Maibaum am 20 Apr. 2018
Bearbeitet: Juri Maibaum am 20 Apr. 2018
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?

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 20 Apr. 2018
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 Kommentar
Juri Maibaum
Juri Maibaum am 20 Apr. 2018
Bearbeitet: Juri Maibaum am 20 Apr. 2018
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by