1
votes

I am using gnuplot 4.6. I have many data files named data_1.dat, data_2.dat,...,data_100.dat. Now I want to plot data from file 'data_i.dat' to file 'figure_i.eps'. Of course I can do this sequentially for every file data_i.dat like this:

set term postscript eps enhanced color
set out 'figure_i.eps'
pl 'data_i.dat'
set out
set term wxt

If the number of files is too large, this is not a good method. I know that it is possible to use 'do' command in gnuplot 4.6. Hence something like following could perhaps be done:

set term postscript eps enhanced color
do for [i=1:100] {
set out 'figure_i.eps'
pl 'data_i.dat'
set out
}
set term wxt

However, I don't know how do really specify input and output files inside the loop such that correct numbers will be picked up automatically. Any advice is highly appreciated. Thanks in advance.

1

1 Answers

4
votes

You can use sprintf inside your loop:

...
outFile=sprintf("figure_%d.eps", i)
dataFile=sprintf("data_%d.dat", i)
set output outFile
plot dataFile ...
...