我可以在gnuplot中定义一个 round 函数,该函数会自动将数字舍入到一个接近的整数(如地板等),而不是前导数字,例如
round(0.00230354) = 0.002 ?
当然,我可以将每个值乘以10的正确幂,然后 floor 。但为了做到这一点,我需要单独查看每个数字。 我想使用该功能来标记颜色条,我可以使用 stats 命令动态确定抽搐位置,用于不同的数据集。
答案 0 :(得分:2)
您最有可能使用undefined
执行此任务(即首先获取感兴趣的数字的“舍入”字符串表示形式,然后通过sprintf
函数将其转换回数字) :
real
因此,就自定义函数gnuplot> x = real(sprintf("%.0E", 0.00230354));print x
0.002
gnuplot> x = real(sprintf("%.0E", 0.00260354));print x
0.003
而言,示例如下所示:
round
或者,如果您只想要可以直接用于标签的字符串表示,那么gnuplot> round(x) = real(sprintf("%.0E", x));
gnuplot> print round(0.00230354);
0.002
转换说明符可能更相关:
g/G