|
From: Ethan A M. <merritt@u.washington.edu> - 2007-08-15 16:03:33
|
On Wednesday 15 August 2007 00:40, plotter wrote:
> > Example:
> > SUM = 0
> > plot 'foo' using 1:(f($2)):assign(SUM = SUM + $2):assign(N = $0)
> > print "Sum of y values is ",SUM
> > print "Mean y value is ", SUM/N
> >
> However I see a couple of disadvantages with this approach of doing this
> in 'using' clause of plot.
>
> Firstly plot lines can get very long and cumbersome already, especially by
> the time one has added linetype title and colour specifiers. Already some
> of the uses I have for assign run to several lines on their own. I think
> anything more than your simple example would make plot lines very hard to
> follow.
The space required to write it out once should be about the same either way.
But yes, I can see that the earlier f(x)=assign("var",expression)
makes it much easier to re-use the definition concisely in multiple plot
commands.
I will have to think about whether there is a way to tweak the
assign(var = expression) variant so that you can be equally concise.
> Second this is post processing. Much of the usefullness of this technique
> comes from the way I used it in a funtion that returns a value to using
> that gets plotted directly. The post processing seems to be a bit of a
> show stopper for the way I was using this.
It would be very easy to move the assignment evaluation to the beginning
of the per-line processing rather than the end. But then it becomes a
problem what to do if the data line turns out to have missing or invalid
entries. The earlier variant already suffers from this (see below).
I'm open to suggestions here.
However, I'm not sure that the post/pre processing choice makes any
fundamental difference in what you can plot. The two variants below should
achieve the same result, right?
old: plot "foo" using 1:(assign("SUM",SUM+$2)) title 'running sum'
new: plot "foo" using 1:(SUM+$2):assign(SUM=SUM+$2) title 'running sum'
One more thing:
The behaviour of the earlier form is poorly-defined in a case like this
A(x) = assign("VAR_A", f(VAR_A))
B(x) = assign("VAR_B", VAR_A + VAR_B)
plot "foo" using 1:(A($2)):(B($3))
OK, you can say "don't do that". The point is that I don't think the order
of evaluation is guaranteed. Furthermore, what happens if column 3 contains
a '?' (missing data) or 'NaN' (illegal value). Does the value of A get
updated or not? What about the value of B? If so, with what value?
Don't we have a problem that A and B can get out of sync?
I'm cc'ing this to the developer's mailing list. Maybe useful suggestions
will come in from a new direction.
Ethan
--
Ethan A Merritt
|