Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gnuplot: Using a string variable to define columns

For various reasons it seems that the easiest way to perform a certain plot is for me to store the column numbers I need in a variable, and then perform a plot command calling that variable.

Is this even possible?

I want to achieve something like:

plot '< paste '.filesString.'' u 1:(columnsString)

Also, the variable 'columnsString' will have a value like

(\$2*\$5+\$(6*2-4)*\$(6*2-1))

for instance, so it needs to be able to evaluate all the (6*2-4) style sums that are in the string. I want to emphasize that this question is only regarding the evaluation of the 'columnsString', the 'filesString' variable is working fine. How can I manage this?

like image 916
Dennis Avatar asked Feb 26 '26 14:02

Dennis


1 Answers

For this you can use set macro. With this setting, you can use a string variable columnString, and put its content somewhere in a command, before this is evaluated:

set macros
columnString = 'column(2)*column(5) + column(6*2-4)*column(6*2-1)'
plot '< paste '.filesString using 1:(@columnString)

I used column() instead of the shorthand $.. to prevent possible problems with escaping (seems like you are calling this from some script).

like image 122
Christoph Avatar answered Mar 01 '26 13:03

Christoph