From: per isakson on
"matlaberboy " <matlaberboy(a)gmail.NOSPAM.com> wrote in message <hvo3jd$sta$1(a)fred.mathworks.com>...
> hello.
> I have a CSV file. I don't know in advance what size it is (rows, cols) nor do I know the types associated with each col. The CSV contains mixed types.
>
> url = 'http://www.bea.gov/national/nipaweb/csv/NIPATable.csv?TableName=6&FirstYear=1900&LastYear=2011&Freq=Qtr';
>
> str = urlread(url);
>
> The above link is one such example of such a file. As it updated in "real-time" we never know how many cols it has etc
>
> I would like to get the whole contents of the CSV file loaded into a variable, probably with all the types changed to char. Hence I can search for the data I want (eg 'Gross domestic product') in that variable and then convert the asscoiated data to the correct type.
>
> Matlab seems particuarly bad at doing this; there are so many methods (dlmread, textscan, urlwrite etc etc) and loads of very complex file exchange submissions.
>
> Many Thanks


The two lines you provide puts the content of the file into the variable named str.
The function strfind helps you locate substrings in the string, str.
>> strfind( str, 'Gross domestic product' )
ans =
3265

The "lines" are separated with char(13)
>> is = str == char(10);
sum(is)
is = str == char(13);
sum(is)
ans =
0
ans =
38

/ per