Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gnuplot get value of a particular data in a datafile? (with or without using stats)

Tags:

gnuplot

Imagine I have a data file with two column. In gnuplot running

stats 'datafile' u 1:2

allows me find the minimum and maximum for the two columns. The variable STATS_index_min_x and STATS_index_min_y give respectively the index of the minimum for the first and second column. It says in the documentation that they are such that

data[STATS_index_min_x] == STATS_min_x

Now imagine that need to have access to data[STATS_index_min_x-1] or data[STATS_index_min_x+1]. How can I do that ? Actually how can I access any particular data of any column in gnuplot?

like image 234
PinkFloyd Avatar asked Jan 05 '23 22:01

PinkFloyd


2 Answers

As far as I know, you cannot access the data in your file in this way (i.e. like an array).

On Linux/cygwin, you could work with an helper function that extracts the value directly from the underlying datafile using awk. You can define the following function:

getValue(row,col,filename) = system('awk ''{if (NR == '.row.') print $'.col.'}'' '.filename.'')

If your datafile is called datafile and contains these values:

1  1.4
2  4.3
3  2.5
4  0.0
5  9.0

Which gives:

gnuplot> print getValue(3,1,"datafile")
3
gnuplot> print getValue(1,2,"datafile")
1.4
like image 81
Raphael Roth Avatar answered Jan 08 '23 13:01

Raphael Roth


Gnuplot hadn't been designed for this, but you can cheat a little bit ;-)

stats 'datafile' u 1:2
plot[STATS_index_max_x+1:STATS_index_max_x+1.5] 'datafile.dat' u 0:1

then GPVAL_DATA_Y_MIN (and GPVAL_DATA_Y_MAX) contains the value you wanted.


NOTE

plot '<datafile>' u 0:<column>

plots the desidered column versus 0,1,2...

like image 45
Tom Solid Avatar answered Jan 08 '23 12:01

Tom Solid