问题
I use Gnuplot and I would like to save values of a datafile into a variable with condition. For example, I have the following datafile 'example.dat':
columnl column2
5 7.0
3 4.0
7 6.0
In my gnuplot script, I would like to be able to write:
variable = " in the file 'example.dat' ($1)==5 ? $2 : 1/0 "
which would be here the same as:
variable = 7.0
of course the value depends on the datafile.
So is it possible?
If not, is it possible without condition?
回答1:
This is how I worked around the problem:
A=""
plot file u (A=A.sprintf(' %g',$2), $1):2
All the entries from column 2 will be written to A, which you can access then via:
word(A,i)
where i is the number of the raw (starting at 1) words(A) gives you the total length.
来源:https://stackoverflow.com/questions/21309122/gnuplot-how-to-save-datafile-values-into-a-variable-with-condition