The idea is the same as @andyras 's, but using stats
.
To answer the title, you can use every ::n::n
, where n is the record (i.e. datapoint) number of choice. Records are numbered from 0, so if you want the first line, it should be every ::0::0
. every
can be used in either plot
, splot
, or stats
(usage of every
in stats
is undocumented). I prefer stats
since it doesn't plot anything, but it does clutter your gnuplot console (EDIT to avoid the cluttered console use nooutput
at the end of the stats
command). Also, you can use using
to make arbitrary assingments.
For example, to save the second column of your first record,
stats "my2columndata.dat" u (firstdatapoint=$2) every ::0::0
Now to get the last record, you can use the number of records saved by stats
, and use that as the record number in every
,
stats "my2columndata.dat" # this saves the number of records to STATS_records
stats "my2columndata.dat" u (lastdatapoint=$2) every ::STATS_records-1::STATS_records-1
Now you can do the plot that you asked for.
And before I finish, some extra hacks:
Using mgilson's idea of counting columns, you can even save every column to a number of variables. (Note: I'm using shorthands u
for using
, and ev
for every
)
filename = "yourfilename.dat"
r = 0 # record number
good = 1
col = 1
while (good) {
stats filename u (good=valid(col)) ev ::r::r
if (good) {
stats filename u col ev ::r::r
eval(sprintf("v%d=STATS_max",col))
col = col+1
}
}
If the datafile contains 8 columns, then v1
to v8
are now defined.
But I suppose using an external tool is the right way to it (UNIX-likes can use tail/head etc.). Let's blame gnuplot authors for making this possible :)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…