|
From: Ethan M. <eam...@gm...> - 2022-09-16 17:27:06
|
On Friday, 16 September 2022 05:21:16 PDT Geoff Kaniuk wrote:
> Thank you all for the swift replies. This made me realise that my
> looped plot example produces separate plots for each array, but I wanted
> all curves in 1 plot.
>
> Using the eval clue I have come up with a solution looking like this:
>
> STEP1. create a function curves(n)
> to generate the string "ab1 w lp, ab2 w lp"
> ( I wonder if this what Alan Corey meant by search & replace)
>
> STEP2.
> curves = curves(2)
> plotcurves = "plot ".curves
> eval(plotcurves)
>
> Using sprintf to get plotcurves also worked. One slight issue is that I
> had missed a space after the comma separating the plot elements. So the
> generated string "ab1 w lp,ab2 w lp" failed, with plot trying to treat
> it as the name of a single file. However plot ab1 w lp,ab2 w lp is fine.
>
> Although this is a solution for a handful of arrays, is this really the
> only way?
I don't think you can do better than that in version 5.2.
The development version of gnuplot supports a larger set of array
operations including treating them as unitary variables for the
purpose of passing an array to, or returning an array from, a function.
Here is a script that works in 5.5 but not in 5.2:
###
array ab1 = [1,1,1]
array ab2 = [2,2]
array ab5 = [5,5]
array ab67 = [67,67]
list = ""
do for [i = 1:99] {
name = sprintf("ab%d",i)
if (exists(name)) {
list = list." ".name
}
}
print "Now I will plot: ", list
plot for [name in list] value(name) with lp
###
Version 5.2 understands what that script attempts to do but
prints an error "unsupported array operation".
Ethan
|