Octave - error reading data with textscan function

441 views Asked by At

I am trying to read data of the following format with textscan:

date,location,new_cases,new_deaths,total_cases,total_deaths
2019-12-31,Afghanistan,0,0,0,0
2020-01-01,Afghanistan,0,0,0,0
2020-01-02,Afghanistan,0,0,0,0
2020-01-03,Afghanistan,0,0,0,0
2020-01-04,Afghanistan,0,0,0,0
...

(Full data file available here: https://covid.ourworldindata.org/data/ecdc/full_data.csv)

My code is:

# Whitespace replaced with _
file_name = "full_data.csv"; 
fid = fopen(file_name, "rt");
data= textscan(fid, "%s%s%d%d%d%d", "Delimiter", ",", "HeaderLines", 1, ...
  "ReturnOnError", 0);
fclose(fid);

Text scan terminates with an error:

error: textscan: Read error in field 3 of row 421

Row 421 is the center row in the example below:

2020-01-12,Australia,0,0,0,0
2020-01-13,Australia,0,0,0,0
2020-01-14,Australia,0,0,0,0
2020-01-15,Australia,0,0,0,0
2020-01-16,Australia,0,0,0,0
2020-01-17,Australia,0,0,0,0
2020-01-18,Australia,0,0,0,0

I've checked the row it complains about and there is nothing different from the example above. I've replaced all spaces in the file with underscores too. Am I doing something wrong with textcan?

0

There are 0 answers