From: Dan Hensley on
On Thu, 28 Sep 2006 10:33:24 -0700, sunder_79 wrote:

> Hi Fort,
>
> thanks for the response. I haven't used fscanf before but from the
> documentation it seemed like I would need to specify the format of the
> columns - which is what I'm trying to avoid doing. Is there a way to
> read in the file without specifying the format or number of columns. Or
> having all the columns default to the same format?

If the lines have a specified delimiter, just read in the first line as a
string, then parse the line using that delimiter to count the number of
columns. Here are a few more functions for you to look at.

help fgetl
help strread
help strtok

Dan



>
> Thanks,
> Sunder
>
> Fort wrote:
>> Sunder,
>>
>> You could just read in the first line (or the whole header) to
>> determine the number of columns using an fscanf() and then close the
>> file. Compute the number of columns, generate an appropriate format
>> string and read it in using textread/textscan or even just fscanf.
>>
>> --Fort
>>
>>
>> sunder_79(a)yahoo.com wrote:
>> > Hi,
>> >
>> > I have a set of large flat files that I'd like to read in one after the
>> > other in a loop. I'm looking for specific columns of data from each
>> > file. However the number of columns varies from file to file (and there
>> > are lots of them and so it's very timeconsuming to specify the format
>> > for each file). Is there a way to read a file in using textread or
>> > textscan without specifying the number/format of the columns. If I can
>> > do this, then I'd be able to find the appropriate columns that I need
>> > by matching the headers.
>> >
>> > Thanks a lot for your help!
>> > Sunder