nish-ant
nish-ant

Reputation: 119

Calculations using variable columns - gnuplot

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?

Upvotes: 1

Views: 1258

Answers (1)

Vinicius Placco
Vinicius Placco

Reputation: 1731

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!

Upvotes: 3

Related Questions