How to import csv files with more than 100000 columns using csvread

2 views (last 30 days)
I'm trying to import csv files that have 25 rows and >100000 columns of data points.
When the file contains more than 100000 columns or data points per row, csvread is importing the data as a vector rather than matrix. This code reproduces the error on my machine:
x = rand(25,110000);
csvwrite('test.csv',x)
test = csvread('test.csv');
I would like test to be the same size as x but I get vector of size 2750000x1.
Any ideas?
  1 Comment
Jeremy Hughes
Jeremy Hughes on 16 Jul 2015
Hi Sean,
CSVREAD stops trying to count the number of columns at 100,000 and assumes the file contains just one long vector.
I suggest using TEXTSCAN. This code should do what you need.
fid = fopen('test.csv','r');
fmt = repmat('%f',1,110000);
d = textscan(fid,fmt,'Delimiter',',','CollectOutput',true);
test = d{:};
fclose(fid);
Hope this helps,
Jeremy

Sign in to comment.

Answers (0)

Categories

Find more on Data Import and Export in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!