Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the value of a specific element from a different row in gnuplot

Using gnuplot 4.2, is it possible to obtain the value of a specific column/row and use that value somehow?

For example, let's say my datafile contains the following

#1  2
7  13
5  11
23 17
53 12

For a simple plot where column 1 is the x axis and column 2 is the y axis I would:-

plot 'datafile' using 1:2

What I'm trying to do is to normalize the all data in column 2 by the first element in that column (13). Is there a way to do this in gnuplot itself (i.e., without resorting to a scripting language or something to preprocess the data first)?

Cheers

like image 901
fuad Avatar asked Oct 28 '08 05:10

fuad


1 Answers

Using the running averages demo, I managed to achieve a plot normalized to the first value of the second column.

The base variable is used to store the reference value, and the first function initializes base on the first row.

first(x) = ($0 > 0 ? base : base = x)
plot file.dat u 1:(first($2), base/$2)

It should be mentioned that this was not done using gnuplot 4.2.

Edit: Updated using Christoph's advice.

like image 59
Jonatan Lindén Avatar answered Nov 15 '22 11:11

Jonatan Lindén