next up previous contents index
Next: Linetypes, colors, and styles Up: Gnuplot Previous: Glossary   Contents   Index

Iteration

[r][rt][width=3in,keepaspectratio]figure_newsyntax Version 4.6 of gnuplot introduced command iteration and block-structured if/else/while/do constructs. See if (p. [*]), while (p. [*]), and do (p. [*]). Simple iteration is possible inside plot or set commands. See plot for (p. [*]). General iteration spanning multiple commands is possible using a block construct as shown below. For a related new feature, see the summation (p. [*]) expression type. Here is an example using several of these new syntax features:
     set multiplot layout 2,2
     fourier(k, x) = sin(3./2*k)/k * 2./3*cos(k*x)
     do for [power = 0:3] {
         TERMS = 10**power
         set title sprintf("%g term Fourier series",TERMS)
         plot 0.5 + sum [k=1:TERMS] fourier(k,x) notitle 
     }
     unset multiplot



2016-07-27