11

I know how to use $ with using in examples like

plot datafile using f($1):g($2)

to plot functions of column data. But I want to use this feature in a loop:

plot for [c=1:10] datafile using f($(c)):g($(c+1))

Of course this code doesn't work. I guess that if I know how to convert the integer c to a string (or a single ASCII character) then it would work. How can I do it?

(If the same task can be done without conversion of integer to string, that would be fine too.)

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mahdiyar
  • 335
  • 1
  • 3
  • 8
  • Not sure what your placeholder c means? If you want a for loop in gnuplot try something like http://stackoverflow.com/questions/4062999/gnuplot-script-for-loop-within-or-adding-to-existing-plot/4115145#4115145. If you want to split the output depending on the xrange use the ternary operator http://t16web.lanl.gov/Kawano/gnuplot/misc1-e.html – Tom Mar 09 '11 at 19:06
  • 1
    I don't think that gnuplot thinks of _c_ as a string. It rather parses the line and sees that 'c' is not a number and then breaks the interpretation, since this works: plot for [c=2:3] datafile using (f($1)):(g($2)) title sprintf("%d", c) Note that _c_ is interpreted as an integer in the end. – Woltan Mar 11 '11 at 10:15

5 Answers5

17

You can Use intrinsic function sprintf to convert numbers to string

gnuplot>  a=3; b=6;
gnuplot>  plot a*x+b title sprintf("a=%1.2f; b=%1.2f",a,b)
Sergei
  • 1,599
  • 12
  • 21
6

Are you looking for something like:

plot for [c=1:5] datafile using (column(c)):(column(c+1))

This will do: plot datafile u 1:2, "" u 2:3, "" u 3:4, "" u 4:5, "" u 5:6

Luke
  • 11,426
  • 43
  • 60
  • 69
Arun
  • 481
  • 3
  • 9
0
set title sprintf("Polinômio de Taylor no ponto %f ",a)

or the English variant

set title sprintf("Taylor Polynomial at the point %f ",a)

will define the title transforming the number a into the previous string I have use this in a loop, with the Taylor Polynomial calculated previously at the point a, where a containing a number is the governing variable of the while.

slfan
  • 8,950
  • 115
  • 65
  • 78
user3648948
  • 131
  • 1
  • 4
-1

Prepend an empty string if necessary. E.g.:

gnuplot> a=42
gnuplot> print a." questions"
         internal error : STRING operator applied to non-STRING type

gnuplot> print "".a." questions"
42 questions

The first print fails because of a type mismatch. The second one works fine though. Apparently . is left associative.

David Ongaro
  • 3,568
  • 1
  • 24
  • 36
-1

How about something like this? The loop statement could be different depending on the shell you are using. The one below is using bash.

plot '< for i in 1 2 3 4 ; do echo $i ; done' us ($1):($1+1)
Sunhwan Jo
  • 2,293
  • 1
  • 15
  • 13