|
From: Ethan M. <merritt@u.washington.edu> - 2007-05-07 23:51:34
|
The SourceForge end of the gnuplot-bugs mailing list is currently broken. I found this posting via gmane.org (under "bugs") but it doesn't really belong there, so I'm copying it to the developers list with a reply. Synopsis: The suggestion is to allow assignment to a variable inside an expression. This may be useful in order to collect statistics about data points as they are read in Response: I have attached a small patch that implements a new user-visible function: assign("VAR", <expression>) It assigns the current value of the expression to a variable named VAR. NB: this is the _name_ of the variable, not the variable itself. Example: MAX = -999 update_max(x) = assign("MAX", x > MAX ? x : MAX) plot <foo> using 1:($2 + 0. * update_max($2)) print "Maximum data value plotted was", MAX Comments: I'm not sure this will actually accomplish what you want, but please try it out and let us know. If you use this inside a "using" clause, it will slow down data input. For large data files the slowdown is likely to be noticeable. For the use above, it would probably be more convenient to have the update_max(x) function return the current value of x rather than the updated maximum. It's not clear to me how best to achieve that. %%%%%%%% begin forwarded message %%%%%%%%% From: <plotter <at> piments.com> Subject: feature request Newsgroups: gmane.comp.graphics.gnuplot.bugs I have been trying to trick gnuplot into doing some simple tasks it does not seem possible to do but which could be immensely useful. to judge by comp.graphics.apps.gnuplot it seems that there are certain basic tasks that are frequently requested and get a reply along the lines of "gnuplot is not for number crunching". Fine. Gnuplot is a plotting program, not a data processing package but there are an number of trivial tasks like calculating a mean or finding the max of values *calculated* by gnuplot that cant currently be done. Tasks like this are far less complex than function fitting do data or plotting with spline interpolation and would be very valuable in the context of outputting data to a graph. eg how to put a label at the max point of the data. Definately a plotting task and hardly "number crunching" but currently it seems I have do this simple task in an external script. Worse, if I do some fitting and expression evaluation in the plot command , I have to duplicate it all to a table, call an external script and then read in a new file to get the value of the max or mean value of y. all I really need is a means to assign one tiny little variable during plot (directly or from a within a fn ) consider the following that will plot a "sample and hold": xmax=0; max(x)=( (xmax<x)?(xmax=x):xmax ); plot "150tank-txC.data" using 1:(Th6($4)) with lines t "panel out" \ , "150tank-txC.data" using 1:(max(Th6($4))) with lines t "s/h" ; Currently not possible since function parser will not allow C style 'assignment returns a value'. A similar technique could find the min , max, mean or area under graph; in fact it opens a whole range of possibilities that are frequently requested on the list. So how much effort is it? Well without going to the extent of supporting procedure calls from with plot command , adding the above parsing of C style assignments would be simple to add and open the door to some very useful techniques. I hope you will find it worth considering. Kind regards. %%%%%%%% begin forwarded message %%%%%%%%% -- Ethan A Merritt |