gnuplot : how to save datafile values into a variable (with condition)?

蹲街弑〆低调 提交于 2020-01-13 05:53:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!