MATLAB: Am I getting incorrect data when reading a file with varying number of columns using CSVREAD

columnscommacomma separatedcsvcsvreaddatadlmreadMATLABreadseparateduneven

I have the following data in my csv-file, test.csv:
1,2,3,4,5
1,2,3
1,2,3,4
1,2,3
1,2,3,4
1,2
I read in my file with the following command:
data = csvread('test.csv')
Which results in the following incorrect data in MATLAB:
data =
1 2 3 0 0
1 2 3 4 0
1 2 3 0 0
1 2 3 4 0
1 2 3 5 0
1 2 4 0 0

Best Answer

This bug has been fixed for Release 14 (R14). For previous releases, read below for any possible workarounds:
This is a bug in the CSVREAD function from MATLAB.
One possible workaround is to save the file as an Excel spreadsheet, and then load in the data using XLSREAD. For information on XLSREAD and other File I/O routines, please see Technical Note 1602: File I/O Guide.