Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Reading text matrix with NaN to splot

362 views
Skip to first unread message

William Winter

unread,
Apr 23, 2008, 10:48:53 AM4/23/08
to
I'm trying to plot a matrix from a text file where the data values
contain NaNs. The file contents are something like

smallTest.txt
0.0 0.2 0.4 0.6 0.8
0.0 0.3 0.6 0.9 1.2
0.0 0.4 NaN NaN 1.6
0.0 0.5 1.0 NaN 2.0
0.0 0.6 1.2 1.8 2.4

then the commands to gnuplot
set datafile missing "NaN"
splot "smallTest.txt" matrix with lines

which gives the error message
Bad number in matrix

If I change the NaNs in the file to numbers everything works as expected.

My system details
G N U P L O T
Version 4.2 patchlevel 2
last modified 31 Aug 2007
System: Darwin 9.1.0

Sorry if there's something simple I've missed, and thanks in advance
Will

Ethan Merritt

unread,
Apr 23, 2008, 11:09:36 AM4/23/08
to
In article <wtw20-283015....@nntp-serv.cam.ac.uk>,

William Winter <wt...@cam.ac.uk> wrote:
>I'm trying to plot a matrix from a text file where the data values
>contain NaNs. The file contents are something like
>
>smallTest.txt
>0.0 0.2 0.4 0.6 0.8
>0.0 0.3 0.6 0.9 1.2
>0.0 0.4 NaN NaN 1.6
>0.0 0.5 1.0 NaN 2.0
>0.0 0.6 1.2 1.8 2.4
>
>then the commands to gnuplot
>set datafile missing "NaN"
>splot "smallTest.txt" matrix with lines
>
>which gives the error message
>Bad number in matrix
>
>If I change the NaNs in the file to numbers everything works as expected.

The question is, what do you mean by "expected"?
For instance, how would the program contour a matrix with missing data?
How would it interpolate colors when corners are missing?
I guess if a surface is drawn, there would be holes in the surface?

Should Inf (or -Inf) be treated the same as NaN?

In other words, it would easy enough to modify the code so that NaN is
read in. But then what?

--
Ethan A Merritt

Ethan Merritt

unread,
Apr 23, 2008, 6:37:52 PM4/23/08
to
In article <wtw20-283015....@nntp-serv.cam.ac.uk>,
William Winter <wt...@cam.ac.uk> wrote:
>I'm trying to plot a matrix from a text file where the data values
>contain NaNs. The file contents are something like
>
>smallTest.txt
>0.0 0.2 0.4 0.6 0.8
>0.0 0.3 0.6 0.9 1.2
>0.0 0.4 NaN NaN 1.6
>0.0 0.5 1.0 NaN 2.0
>0.0 0.6 1.2 1.8 2.4
>
>then the commands to gnuplot
>set datafile missing "NaN"
>splot "smallTest.txt" matrix with lines
>
>which gives the error message
>Bad number in matrix

Uh oh.
In starting at the code, I see that this message is hiding a serious error.
If you ever see this message, there is a good chance that the program
will die from a memory access error the next time matrix data is read in.

Expect a fix of some sort for the CVS code tree and, depending on how
obviously correct the fix may turn out to be, for the next release version.


>
>If I change the NaNs in the file to numbers everything works as expected.
>
>My system details
> G N U P L O T
> Version 4.2 patchlevel 2
> last modified 31 Aug 2007
> System: Darwin 9.1.0
>
>Sorry if there's something simple I've missed, and thanks in advance
>Will


--
Ethan A Merritt

petero...@gmail.com

unread,
May 29, 2008, 5:11:48 PM5/29/08
to
For me, using gnuplot on Linux Version 4.2 patchlevel 0,
having splot ignoring matrix data elements seems to work if using
"Inf" infinity marker instead of "NaN".
I get holes in the mesh that splot draws. With pm3d color-indexed
height-surface splot I similarly get holes in the surface drawn.
I hope that helps.
Peter
0 new messages