I create some random data in 5 columns and store that as a CSV file. This works fine, my CSV actually contains 1001 rows; my data with the header (I checked this by opening it in my spreadsheet editor). However, when I read it in MATLAB again using csvread, I get an error if I do not specify the delimiter and when I do specify the delimiter data contains only 957 rows, thus the header and first 42 rows are missing. What is going on here?
code:
A = rand(1e3,5);
out = fopen('output.csv','w');
fprintf(out,['ColumnA', ',', 'ColumnB', ',', 'ColumnC', ',', 'ColumnD', ',', 'ColumnE','\n']);
fclose(out);
dlmwrite('output.csv', A, 'delimiter',',','-append');
data = csvread('output.csv',',');
Error:
Error using dlmread (line 139) Mismatch between file and format string. Trouble reading number from file (row 1u, field 1u) ==> ColumnA,ColumnB,ColumnC,ColumnD,ColumnE\n
Error in csvread (line 48) m=dlmread(filename, ',', r, c);
Am I missing something stupid in writing or reading the file?
I am running MATLAB R2012a on a 64bit Windows 7 machine. (Though I hope to upgrade to R2015b in the coming month)