I have a file made of three columns, x, y1 and y2. I need to know the value at which y2 has a maximum. To find the maximum of y2 is easy:
stats 'test2-EDB.dat' u 3
from which I know that the y2 has a maximum on the 6779th line of the file
STATS_index_max = 6779.0
However, what I need it the x value at the 6779th line of the file. Do you have any suggestions? Which optimally are platform independent?
The solution which I have found here (Reading dataset value into a gnuplot variable (start of X series)) was:
at(file, row, col) = system( sprintf("awk -v row=%d -v col=%d 'NR == row {print $col}' %s", row, col, file) )
file="test2-EDB.dat" ; row=STATS_index_max ; col=1
c=at(file,row,col)
However, I doubt that this solutions works without any problems also on windows (no idea, I'm not using it).
With best regards, Leonardo
You can use every
for the stats
command to get the x-value:
stats 'test2-EDB.dat' u 3
stats 'test2-EDB.dat' u 1 every ::STATS_index_max::STATS_index_max
print sprintf("x-value is %e", STATS_max)