I am using gnuplot 5.2.4.
I am doing a for-loop, to analyse in each cycle a different column (or combination of columns) of a file. The column to be used is written in an array and is passed to the commands as a macro.
The code is written in a .plt file that I load in gnuplot.
It looks like this
(here for example I'm using the 1.dat file in the \gnuplot\demo)
:
set macros
array label[2]
label[1]="First_Cycle"
label[2]="Second_Cycle"
array index[2]
index[1]="(column(2))"
index[2]="(column(2)-column(1))"
fileDat = "1.dat"
do for [k = 1 : 2] {
fileExport = sprintf("%s.gif",label[k])
print fileExport
set term gif size 1920,1280 enhanced
set output fileExport
indexk = index[k]
print k," ",index[k]," ", indexk
stats fileDat u @indexk name "DV" #noout
plot fileDat u @indexk ti label[k]
}
indexk is printed correctly at each cycle, however, I obtain the following warning: warning: indexk is not a string variable and the commands stats and plot analise always the column in index[1] at each cycle.
However, if I comment the do for loop and increase the k by hand, the code works correctly, no warning, no problem, like this:
set macros
array label[2]
label[1]="First_Cycle"
label[2]="Second_Cycle"
array index[2]
index[1]="(column(2))"
index[2]="(column(2)-column(1))"
fileDat = "1.dat"
k=2
#do for [k = 1 : 2] {
fileExport = sprintf("%s.gif",label[k])
print fileExport
set term gif size 1920,1280 enhanced
set output fileExport
indexk = index[k]
print k," ",index[k]," ", indexk
stats fileDat u @indexk name "DV" #noout
plot fileDat u @indexk ti label[k]
#}