|
From: sfeam (E. Merritt) <eam...@gm...> - 2011-11-23 02:13:23
|
On Friday, 18 November 2011, gbliu wrote:
> Dear all:
>
> These years gnuplot becomes more and more powerful. In sense, it's a
> quasi-programming-language. String variable is supported since ver4.0, and {}
> blocks and loops are supported in ver4.5. But a basic function, array, is still
> not supported now. I think this is highly needed, especially when loops are
> supported.
>
> ------------------------
> e.g.
>
> I have a data file with many columns, but want to plot only some columns, say,
> column 2, 3,6,7,9,15,24. And the lengeds for each column differ. Now, I can only
> use the command as follow:
>
>
> plot 'data' u 1:2 title '...', '' u 1:3 title '...', '' u 1:6 title '...',\
> '' u 1:7 title '...', '' u 1:9 title '...', '' u 1:15 title '...',\
> '' u 1:24 title '...'
>
> Although gnuplot support "plot for [i=...]" now, but it cannot be used here,
> because the column numbers is not regular. In this case, array is needed to
> simplify the plot command.
>
> Suppose there are two arrays, col and str:
> col[1]=2; str[1]='...'
> col[2]=3; str[2]='...'
> col[3]=6; str[3]='...'
> col[4]=7; str[4]='...'
> col[5]=9; str[5]='...'
> col[6]=15; str[6]='...'
> col[7]=24; str[7]='...'
>
> now, I can use the following more concise command:
>
> plot for [i=1:7] 'data' u 1:(column(col[i])) title str[i]
I can imagine numerical uses for arrays, but your example seems to
be just a request for an easier way to order variable names.
The following works currently, for example:
col1 = 2; str1 = 'title 1 with multiple words'
col2 = 3; str2 = 'title 2 etc'
col3 = 6; str3 = 'title 3'
...
COLUMN = "col"
TITLE = "str"
plot for [i=1:7] 'data' u 1:(column(value(COLUMN.i))) title TITLE.i
I grant you that column(value(COLUMN.i)) is a bit awkward compared
to just col[i], but if we cleaned up that syntax a bit would it address
your needs? I really don't see anything in this particular request that
requires an array in the usual mathematical sense.
|