gnuplot:如何与NaN进行比较?

编程入门 行业动态 更新时间:2024-10-23 21:37:06
本文介绍了gnuplot:如何与NaN进行比较?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这里有一些关于此的主题(使用javascript,c ++等),但尚未找到适合gnuplot的主题.

There are several topics here about this (in javascript, c++,...), but haven't yet found one for gnuplot.

基本上,我想在标签中将"nan"替换为"---".

Basically, I want to replace "nan" with "---" in labels.

我知道我可以设置 NaN ="---" ,但是 NaN 的行为就像一个字符串,需要修改其他代码.

I know that I can set NaN = "---" but then NaN behaves like a string and other code needs to be adapted.

### How to compare to NaN? NaN = GPVAL_NaN # default value for NaN a = NaN print (a==NaN ? "---" : sprintf("%g",a)) print (a==NaN ? sprintf("%g",a) : "---") print (a!=NaN ? "---" : sprintf("%g",a)) print (a!=NaN ? sprintf("%g",a) : "---") a = 123 print (a==NaN ? "---" : sprintf("%g",a)) print (a==NaN ? sprintf("%g",a) : "---") print (a!=NaN ? "---" : sprintf("%g",a)) print (a!=NaN ? sprintf("%g",a) : "---") ### end of code

结果:

NaN --- NaN --- 123 --- 123 ---

因此,没有一种组合可以完成这项工作.

So, none of the combination does the job.

最后,我发现以下内容似乎可行.

Finally, I found that the following seems to work.

print (a/a == 1 ? sprintf("%g",a) : "---")

我的问题:

a/a 是否总是精确地为 1 ,或者在特殊情况下是否可能存在舍入错误?是这样做的方式"还是我忽略了任何事情?

Will a/a always be exactly 1 or could there potentially be rounding errors in special cases? Is this "the" way how to do it or did I overlook anything?

推荐答案

只是为了不让这个问题出现而没有答案...

just for the sake of not letting this question appearing unanswered...

一种比较变量 a 是否为 NaN (至少在gnuplot中)(并至少对其进行处理)的最简单方法:

Probably, the easiest way to compare if a variable a is NaN or not (at least in gnuplot) and do something with it:

print (a == a ? sprintf("%g",a) : "---")

在SO上对某些编程语言进行讨论之后,人们开始辩论 NaN == NaN 或 NaN!= NaN 或两者都不是.

Following some discussions on some programming languages here on SO, people are debating about NaN==NaN or NaN!=NaN or neither of them.

如果与数据中的字符串"NaN" 进行比较,请参见上面的@Christoph注释.

And in case of comparison to the string "NaN" in data: see @Christoph's comment above.

更多推荐

gnuplot:如何与NaN进行比较?

本文发布于:2023-10-23 14:02:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1521033.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:gnuplot   NaN

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!