From: us on
"John " <astro_nut(a)hotmail.com> wrote in message <i2kvc3$kvg$1(a)fred.mathworks.com>...
> I have a txt file that is of unknown column/row length or size. Similar to this:
>
> Title1 Title2 Title3 ...
> 1 2 3
> 1 2 3
> 1 2 3
>
> ...you get the point. It is basically a /t delimited txt file exactly like a excel sheet. How do I use the textread function similar to the [file, text] = xlsread(). Is that possible?
>
> Thanks,
> Clay

a hint:

help textread; % <- now, look at the DELIMITER option...

us
From: John on
Walter Roberson <roberson(a)hushmail.com> wrote in message <i2l0s5$no9$1(a)canopus.cc.umanitoba.ca>...
> John wrote:
> > I have a txt file that is of unknown column/row length or size. Similar
> > to this:
> >
> > Title1 Title2 Title3 ...
> > 1 2 3
> > 1 2 3 1 2 3
> >
> > ...you get the point. It is basically a /t delimited txt file exactly
> > like a excel sheet. How do I use the textread function similar to the
> > [file, text] = xlsread(). Is that possible?
>
> It probably is not possible with textread() unless you don't mind all of the
> data being pushed together into one continuous vector.
>
> My approach would probably be to fopen() the file, fgetl() to read the header
> line, ftell() to record the current position, fgetl() to read the first line
> of data, then
>
> numcols = 1 + sum(InputLine == sprintf('\t'));
>
> then fseek() back to the remembered position, then
>
> textscan(fid, repmat('%f', 1, numcols), 'Delimiter', '\t', 'CollectOutput', 1)
>
> then fclose()


Thanks, that was the direction I needed to head in. I eventually used this format:

file = fopen(go.txt);
text = fgetl(file);
position = ftell(file);
firstline = fgetl(file);
numcols = 1 + sum(text == sprintf('\t'));
A = fscanf(file,'%g %g', [numcols inf]);
fclose(file);
file = A';

so sorta in that direction. Appreciate the help.

Regards,
Clay