I want to generate a gnuplot plot command programmatically, like:
plotline = sprintf(\"\'datafile1.dat\' using %d:3 with points, \'%s\' using %d:3 with point
In order to construct such a plot command from some strings, you can use eval
to execute the commands contained in a string:
plotline = 'x title "mytitle"'
eval('plot '.plotline)
Alternatively you can use set macros
:
set macros
plotline = 'x title "mytitle"'
plot @plotline
This replaces @plotline
with the content of the string variable plotline
before executing the command. Using plot plotline
interpretes the content of plotline
as file name. Note, that as of version 4.6 macros don't work properly in loops, but eval
works fine.
BTW: If you don't specify your own title, then the actual plot statement is written in the plot legend. But that can't be written to the terminal output.