MATLAB: Textscan stopping before the end of the file

csvtextscan

Hello,
I'm using textscan to pull data off a 382 line .csv file, however it seems to think it's done at line 26 as that's where it stops retrieving data. It's working perfectly for those 26 lines and the format of the data doesn't look like it changes among any of the lines.
This is lines 26 and 27 from the .csv:
26, B, blank, blank, blank, blank, blank, blank, 643.5, 5.28, 5.39, 0, 0, 9.05, 1.68, email, spark
27, C, blank, blank, blank, blank, blank, blank, 645.4, 5.5, 5.39, 0, 0, 8.93, 1.64, email, spark
This is the code:
clear all
FID=fopen('masterjustdata.csv');
datacell = textscan(FID, '%d%c%s%f%f%f%c%f%f%f%f%f%f%f%f%s%s', 382, 'Delimiter', ',');
fclose(FID);
Anyone know possibly why it would do this?

Best Answer

Ok I figured it out. In column 7, where I hope to be reading a "N" or "Y", sometimes the data is blank. Using the '%c', when there is a blank, it will read in the invisible comma (as a .csv, visible in .txt format) being used as a delimiter meaning that it will use the next comma as a delimiter and cut the whole line 1 object short.
I simply changed the '%c' to '%s' and it stopped reading the comma and just read in a blank cell. Just to learn, could someone explain why %c would read in the delimiter comma while '%s' doesn't?
Related Question