From: Nick Carriere on
I'm trying to read in a csv file with this format...

date, time, 0.1, 0.2, 0.3, 0.4, text
date, time, 0.5, 0.6, 0.7, 0.8, text
date, time, 0.9, 1.0, 1.2, 1.3, text

The numbers I included are arbitrary, they could be whatever. The number of numerical columns can also vary, but the first two columns will always be the date and the time. Occasionally, the last column will be a text value but sometimes that column will not even be there.

Normally, I would use csvread, but it doesn't work because of the last text column. What is the best way to get around this? I'm not really sure how to use textscan in this situation because the number of columns varies.

The data I need to use is always the first 3 columns after the time column. I don't need any of the other data and it doesn't have to be stored in memory or anything.
From: Leslie McBrayer on
> I'm trying to read in a csv file with this format...
>
> date, time, 0.1, 0.2, 0.3, 0.4, text
> date, time, 0.5, 0.6, 0.7, 0.8, text
> date, time, 0.9, 1.0, 1.2, 1.3, text
>
> The data I need to use is always the first 3 columns after the time
> column. I don't need any of the other data and it doesn't have to be
> stored in memory or anything.
>

As you mentioned, I would use textscan, and tell it to disregard everything
you don't need using %*[^\n] (that is, skip everything until you reach a
newline character). For example,

fid = fopen('myfile.csv');
mydata = textscan(fid, '%*s %*s %f %f %f %*[^\n]', 'delimiter', ',');
fclose(fid);

You might also consider using the 'CollectOutput' parameter in the call to
textscan. For more information,

>> doc textscan


From: Nick Carriere on
"Leslie McBrayer" <lmcbrayer(a)mathworks.com> wrote in message <i24cts$r0a$1(a)fred.mathworks.com>...
> > I'm trying to read in a csv file with this format...
> >
> > date, time, 0.1, 0.2, 0.3, 0.4, text
> > date, time, 0.5, 0.6, 0.7, 0.8, text
> > date, time, 0.9, 1.0, 1.2, 1.3, text
> >
> > The data I need to use is always the first 3 columns after the time
> > column. I don't need any of the other data and it doesn't have to be
> > stored in memory or anything.
> >
>
> As you mentioned, I would use textscan, and tell it to disregard everything
> you don't need using %*[^\n] (that is, skip everything until you reach a
> newline character). For example,
>
> fid = fopen('myfile.csv');
> mydata = textscan(fid, '%*s %*s %f %f %f %*[^\n]', 'delimiter', ',');
> fclose(fid);
>
> You might also consider using the 'CollectOutput' parameter in the call to
> textscan. For more information,
>
> >> doc textscan
>


Worked perfectly. Thanks.