help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: read only a certain number of lines using textread


From: Andy Buckle
Subject: Re: read only a certain number of lines using textread
Date: Thu, 19 Aug 2010 08:18:21 +0100

On Thu, Aug 19, 2010 at 1:28 AM, Tim Rueth <address@hidden> wrote:
> I wish to read only a certain number of lines of a text file using
> textread().  For example, I have an input file:
>
> 1    2
> 3    4
> 5    6
> 7    8
>
> Let's say I want to read the first n rows into var1 and var2.  I would say:
>
> [var1 var2] = textread(infile, "%f %f", n);
>
> This doesn't seem to work...textread will read all of the lines into var1
> and var2, as if "n" didn't exist.  Is this a bug, or am I doing something
> wrong?  (I'm running version 3.2.3 on Vista.)
>
> Also, let's say I have a text string, "foo" at the end of the file, like so:
>
> 1    2
> 3    4
> 5    6
> 7    8
> foo
>
> If I use textread() to read the first 4 rows into var1 and var2, is there a
> way to then read "foo" into a string variable?
>
> Thanks,
>
> --Tim

Maybe fopen, get one line at a time with fgetl and test if the line
has numbers or other chars on before handling. Code snippet for
vaguely similar thing here.
http://octave.1599824.n4.nabble.com/easy-problem-for-expert-users-td2264180.html
If will be slow for a big file.

(Tim - sorry, I meant to reply-all the first time round)

-- 
/* andy buckle */



reply via email to

[Prev in Thread] Current Thread [Next in Thread]