1

I want to multiply 2 columns, where the index of one of the columns is given as a variable. I tried to multiply column 2 with column ind as shown below:

do for [j=1:4]{
    ind = (j-1)*5+1
    plot '../out/coeff.dat' using 1:($2*$ind) notitle with lines
}

I get this error: Column number expected.

I guess that the error might be in the usage of $ind as using a numerical value, eg: 1:($2*$3) or simply 1:ind works fine.

What is the correct syntax to perform arithmetic operation with a variable column?

nish-ant
  • 119
  • 3
  • 15

1 Answers1

2

You can use the column() argument for that:

plot '../out/coeff.dat' using 1:($2*column(ind)) notitle with line

I tested on gnuplot 5.2 and it worked as expected. Also see this link. Hope it helps!

Vinicius Placco
  • 1,683
  • 2
  • 14
  • 24