Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Variable for data column number?

6,609 views
Skip to first unread message

Ingo Thies

unread,
Apr 29, 2008, 5:33:47 AM4/29/08
to
Hi all,

I want to plot large data file sequences from computer-generated Gnuplot
scripts. Such a script consists of dozens (or even hundreds) of plot
commands, and the computer-generated script is being loaded from a
driver script via the load command. The data are divided in columns as
usual. I now want to select the columns to be used for plotting by
setting a switch in the driver file.

Normally, data file columns are specified with e.g.

plot 'file' using 1:2

or

plot 'file' using (f($1)):(f($2))

I found that in the former case one could replace the column numbers by
integer variables, e.g.

c1=1;c2=2
plot 'file' using c1:c2

But is it also possible to use variables for column numbers as a
function argument? "$c1" or similar don't work. For now, I can only do
this by replacing the column specifier in all the lines by
search&replace, but a global switch would be much more convenient.

Does anyone have any hints if this can be done?

Ingo

Juergen Wieferink

unread,
Apr 29, 2008, 7:33:31 AM4/29/08
to
Ingo Thies wrote:
> c1=1;c2=2
> plot 'file' using c1:c2
>
> But is it also possible to use variables for column numbers as a
> function argument? "$c1" or similar don't work. For now, I can only do
> this by replacing the column specifier in all the lines by
> search&replace, but a global switch would be much more convenient.

This could be done using macros "help macro", but the clean way is
via the column() function (help column) [untested]:

c1=1;c2=2
plot 'file' using (column(c1)):(column(c2))


Juergen

Ingo Thies

unread,
Apr 29, 2008, 11:37:04 AM4/29/08
to
Juergen Wieferink wrote:

> This could be done using macros "help macro", but the clean way is
> via the column() function (help column) [untested]:
>
> c1=1;c2=2
> plot 'file' using (column(c1)):(column(c2))

Ah, this works fine, thanks!

Ingo

andreas.b...@gmail.com

unread,
Jan 30, 2020, 11:53:04 AM1/30/20
to
Thanks, This works amazing if one wants to do math on each entry in a column, but directly in a bash script, for example subtracting some number from every entry:

#!/bin/bash

gnuplot <<-EOF

set terminal pdf
set output "test.pdf"
plot "data.dat" u 1:(column(2)-2.63E-02) with lines

EOF

evince test.pdf

0 new messages