MATLAB: Importing large amounts of text and numerical data from csv or txt files

csvtextreadtextscan

Hi everybody
I have a very large csv or txt file with numerical as well as text data. I am looking for a way to import this data, beginning from the third row. The text strings in the data ("NA") should be represented as NaN.
The original csv data represents approx. 1000 columns and 500 rows, so specifying the handling of each column is not feasible.
Any ideas?
Thank you, best,
Chris

Best Answer

numcols = 1000;
fmt = repmat('%f',1,numcols);
fid = fopen('YourFile.csv', 'rt');
indata = textscan(fid, fmt, 'Headerlines', 2, 'Delimiter', ',', 'TreatAsEmpty', 'NA', 'CollectOutput', 1);
fclose(indata);
indata = indata{1};