Why am I getting incorrect data when reading a file with varying number of columns using CSVREAD?

5 views (last 30 days)
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

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
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.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!