Bryan Wright
Bryan Wright

Reputation: 157

Can you exec a string in gnuplot?

In gnuplot, is there any way to specify a command in a variable, like:

command = "plot x**2 with lines"

and then "exec" that command later, using something like:

exec command

Upvotes: 1

Views: 245

Answers (1)

Thor
Thor

Reputation: 47229

Use eval:

echo help eval | gnuplot
 The `evaluate` command executes the commands given as an argument string.
 Newline characters are not allowed within the string.

 Syntax:
       eval <string expression>

 This is especially useful for a repetition of similar commands.

 Example:
       set_label(x, y, text) \
         = sprintf("set label '%s' at %f, %f point pt 5", text, x, y)
       eval set_label(1., 1., 'one/one')
       eval set_label(2., 1., 'two/one')
       eval set_label(1., 2., 'one/two')

 Please see `substitution macros` for another way to execute commands
 from a string.

Upvotes: 1

Related Questions