I am automating a task to create small graphs using gnuplot. And I need to pass the column number from the datafile that is to be plotted
pfile=system(\"echo
You could also pass the column number via command line
gnuplot -e "colnum=$colnum" script.gp
and your script.gp
contains
plot pfile using 4:(column(colnum))
This is an alternative to @EWCZ's answer. Any variable initialized using the system
command is treated as a string: in your case, colnum="2"
(with quotes). You can transform it to an integer by adding zero:
# first option
plot pfile using 4:(column(colnum+0))
# second option
colnum = system("echo $colnum") + 0
plot pfile using 4:(column(colnum))
As a side note, your task could be more flexible (easier to automate) by using @Christoph's answer; better if you have gnuplot 5.0
because you can pass arguments to a gnuplot script directly
it seems that one has to do colnum=int(system("echo $colnum"))
so that the variable colnum
is interpreted as an integer and not a string