本文档演示了如何检查变量是否先前已在gnuplot脚本中定义.
来自doc的示例:
a = 10
if (exists("a")) print "a is defined"
if (!exists("b")) print "b is not defined"
Run Code Online (Sandbox Code Playgroud)
但是,是否可以检查先前是否已定义过某个功能?
换句话说,有没有办法做到以下几点:
f(x) = 2*x
if (exist("f(x)") print "Function is defined"
Run Code Online (Sandbox Code Playgroud)
谢谢!
每个用户定义的函数都可以作为带有前缀的特殊变量GPFUN_:
f(x) = 2*x
show variables GPFUN
Run Code Online (Sandbox Code Playgroud)
印刷
Variables beginning with GPFUN:
GPFUN_f = "f(x) = 2+x"
Run Code Online (Sandbox Code Playgroud)
所以你可以检查该功能
f(x) = 2*x
if (exist("GPFUN_f") print "Function f is defined"
Run Code Online (Sandbox Code Playgroud)