Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define a function without arguments in gnuplot?

Tags:

gnuplot

I want to define a function which returns a random number:

gnuplot> rnd() = int(rand(0)*2**24)
         ^
         invalid command

I need add a parameter x to stop the error message:

gnuplot> rnd(x) = int(rand(0)*2**24)

Is it possible to define a function without parameters?

like image 875
kev Avatar asked Jan 19 '26 12:01

kev


1 Answers

I don't think that is possible (look at the syntax for functions in help user-defined). As far as I can tell -- using rand is the only time when this is useful -- In all other cases your "function" would just evaluate to a constant. I'm guessing the gnuplot devs just haven't thought of this (interesting) corner case, or they didn't think it useful enough to implement.

I hope that I'm wrong about this and somebody else comes along and proves it, but I don't think I am. I think the easiest workaround it to just pass a parameter as you've already mentioned. If you really don't like that, you could use a macro:

set macro
rnd="(int(rand(0)*2**24))"
print 5+@rnd
like image 126
mgilson Avatar answered Jan 22 '26 08:01

mgilson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!