RE: ReadList of Data containing "nan"
- To: mathgroup at smc.vnet.net
- Subject: [mg32816] RE: [mg32798] ReadList of Data containing "nan"
- From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
- Date: Thu, 14 Feb 2002 01:43:33 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
> -----Original Message-----
> From: Adalbert Hanssen [SMTP:hanssen at zeiss.de]
To: mathgroup at smc.vnet.net
> Sent: Tuesday, February 12, 2002 12:24 PM
> To: mathgroup at smc.vnet.net
> Subject: [mg32798] ReadList of Data containing "nan"
>
> Hi, MathGroup,
>
> from a measuring instrument, I get an tab-delimited ASCII file of records,
> each consisting of five numbers.
>
> Up to now, I used to read those records like this (I deliberately skip the
> first two lines):
>
> fil=OpenRead[fileName];
> liste={}; (* start with an empty list
> *)
> Read[fil,String]; (* skip the first and the *)
> str=Read[fil,String]; (* second line in the file *)
> While[(str=Read[fil,String])=!=EndOfFile
> ,strstr=StringToStream[str];
> zeile=ReadList[strstr, Real, WordSeparators->{"\t"}];
> Close[strstr];
> liste=Append[liste,zeile];
> ];
> Close[fil];
> (* now liste contains all the data from the file *)
>
> This works fine for me. Now I am getting results, which have lines, where
> one or more of the numbers in a line are "nan" because of an out-off-range
> condition of the measuring instrument. I want to read those lines
> nevertheless, but I want the "nan"-items be represented by Indeterminate
> in Mathematica.
>
> Which is the best way to read all the data simultaneously converting the
> figures "nan" to Indeterminate in Mathematica?
>
>
> kind regards
>
> Dipl.-Math. Adalbert Hanszen
>
[Hartmut Wolf]
Adalbert,
who knows? Consider this:
astring="1.\t2.\tnan\tnan\t5."
1. 2. nan nan 5.
strstr=StringToStream[astring];
(zeile=Block[{Times=Sequence,nan=Indeterminate},
ReadList[strstr,Expression,
WordSeparators->{"\t"}]])//InputForm
{1., 2., Indeterminate, Indeterminate, 5.}
--
Hartmut