|
From: Ethan A M. <sf...@us...> - 2011-11-18 20:32:11
|
On Friday, November 18, 2011 01:43:29 am 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.
Array support has been suggested before, but no one has stepped up to
do the work :-)
In your particular case it is possible to use the existing syntax
plot for [COL in "2 3 6 7 9 15 24"] 'data' using 1:(column(int(COL))
Generalizing this a little bit, you could even do
COL = "2 3 6 7 9 15 24"
TITLE = "title2 title3 title6 title7 title9 title15 title24"
plot for [i=1:7] 'data' using 1:(column(int(word(COL,i)))) title word(TITLE,i)
Ethan
>
> 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]
>
> ------------------------
>
> Therefore, array is highly suggested to be supportted by gnuplot!
>
> Yours, faithfully
>
> gbliu
>
|