help-octave
[Top][All Lists]
Advanced

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

Re: NaN


From: Matt Funk
Subject: Re: NaN
Date: Thu, 18 Nov 2004 19:32:25 +0000
User-agent: KMail/1.6.2

I am probably too much of a retard, but it gives me:

terminal:
syntax error
>>>     str = fgets(program_input_handle);  # read one line from the opened 
file

for the code snippet:
program_inputfile = sprintf('octave_output/simple_MaxError.dat');       
program_input_handle = fopen(program_inputfile,'r');  
for j=1:5
        junk = fgets(program_input_handle) %grab junk at beginning of file
end
str = fgets(program_input_handle);  # read one line from the opened file
row_vector_of_data = str2num(str)
fclose(program_input_handle);

Anyway, but did it a little different way than you with fscanf and filepoiner 
manipulation. 

thanks anyway
mat




On Friday 19 November 2004 01:43, Paul Laub wrote:
> Matt,
>
> Instead of fscanf(), you might try fgets() followed by str2num(). The
> following lines work for me even when file.txt contains a NaN. (I am
> using Octave 2.1.57 running on Cygwin and Windows 2000.)  This is not
> likely to be an efficient method, but it might suffice.
>
> fid = fopen("file.txt", "r");
> str = fgets(fid);  # read one line from the opened file
> row_vector_of_data = str2num(str);
>
> Hope this helps,
>
> Paul Laub
>
> On Thu, 18 Nov 2004 17:33:13 +0000, Matt Funk <address@hidden> wrote:
> > Hi all,
> >
> > I am trying load a 2D vector from a text file that was actually saved out
> > by another octave script via the save fcn. Anyway, the load() didn't work
> > so i used fscanf. That works fine, and it reads all the values in
> > correctly until i hit the first NaN in the vector (there are several) and
> > after that it doesn't read correctly anymore. In fact it reads all zeros
> > after that regardless if it's a NaN or a good value.
> >
> > Are there any quick fixes for this situation. It'd be REALLY nice if i
> > could read those in since i have a lot of files to read in.
> >
> > Also, when i used the load() fcn it read something in but it is a 1x1
> > entity, whereas my vector is something like 10x25. Looking at that thing
> > it prints the right vector on the terminal, but i can't index it as a
> > vector (obviously since it is a 1x1)
> >
> > so, any fixes?
> >
> > thanks
> > mat
> >
> > -------------------------------------------------------------
> > Octave is freely available under the terms of the GNU GPL.
> >
> > Octave's home on the web:  http://www.octave.org
> > How to fund new projects:  http://www.octave.org/funding.html
> > Subscription information:  http://www.octave.org/archive.html
> > -------------------------------------------------------------



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

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