help-octave
[Top][All Lists]
Advanced

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

Re: Including NaNs in a data file?


From: c.
Subject: Re: Including NaNs in a data file?
Date: Wed, 5 Nov 2014 14:26:36 +0100

On 5 Nov 2014, at 13:55, Alasdair McAndrew <address@hidden> wrote:

> I'm setting up a matrix of student marks; using NaNs for non-existent data: a 
> question not attempted.  I'd like to be able to store this as ascii text 
> outside of Octave, with a row looking something like
> 
> 5 2 N 3 4 N N 3 6 4
> 
> the N's indicating questions not attempted.  I can read this into Octave with 
> "fileread", and I get a long string, which I can then fiddle with to turn 
> into numeric values and NaNs.  The function "dlmread" is more convenient, but 
> converts all non-numeric data to zeros.
> 
> Is there an easy way to store NaNs in an ascii file, and how then can that 
> file be best read into Ocatve?
> 
> Thanks,
> Alasdair
> 


Let asciifile.txt contain the following string:

 1.00000000e+00 1.00000000e+00 NaN 0.00000000e+00 2.00000000e+00 3.00000000e+00 
NaN 3.00000000e+00 1.00000000e+00 1.00000000e+00

you ca simply load this into a variable as follows:

>> a = load ("asciifile.txt")
a =

     1     1   NaN     0     2     3   NaN     3     1     1

BTW, the example below uses NaN because you said you wanted to use that,
but actually "NA" should be a more appropriate value to represent missing 
data rather than "NaN".

"NA" and "NaN" are different values in Octave.

c.






reply via email to

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