From: John on
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
From: Walter Roberson on
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()