Search code examples
gnuplot

Gnuplot: store last data point as variable


I was wondering if there is an easy way, using Gnuplot, to get the last point in a data file say data.txt and store the values in a variable.

From this question, accessing the nth datapoint in a datafile using gnuplot I know that I can get the X-Value using stats and GP_VAL_DATA_X_MAX variable, but is there a simple trick to get the corresponding y-value?


Solution

  • If you want to use Gnuplot, you can

    plot 'data.txt'
    plot[GPVAL_DATA_X_MAX:] 'data.txt'
    show variable GPVAL_DATA_Y_MAX
    

    OR

    plot 'data.txt'
    plot[GPVAL_DATA_X_MAX:] 'data.txt'
    print GPVAL_DATA_Y_MAX