Re: Why for can't print? (and suggestions about help print)

Tatsuro MATSUOKA <[email protected]> Mon, 24 Jan 2022 13:42:49 +0900 (JST)
Newsgroups gmane.comp.graphics.gnuplot.user
Message-ID <[email protected]>
Hello

 print "".x. ",".f(x). ",".g(x)

??

gnuplot> x=12
gnuplot> print "".x
12
gnuplot> x=12.01
gnuplot> print "".x
         internal error : STRING operator applied to undefined or non-STRING variable


The expression "".x seems to be only valid if x is an integer or a string.
The expression " print "".x. ",".f(x). ",".g(x) " are not invalid when x is integer nor string.

Valid statement is 
  print x,", ", f(x), ", " , g(x)
or use "sprintf "as I suggested in the previous mail.
  print sprintf("%f, %f, %f", x, f(x), g(x))

Tatsuro



> ----- Original Message -----
> 
> From: "Marc Chantreux" <[email protected]>
> To: "[email protected]" <[email protected]>
> Date: 2022/01/23 日 22:55
> Subject: [Gnuplot-info] Why for can't print? (and suggestions about help print)
> 
> 
> hello people,
> 
> I'm considering using gnuplot to replace bc in some cases.
> 
> There the for loop can be used for ploting and setting things.
> as the help says
> 
>        plot for [filename in "A.dat B.dat C.dat"] filename using 1:2 with lines
>        plot for [basename in "A B C"] basename.".dat" using 1:2 with lines
>        set for [i = 1:10] style line i lc rgb "blue"
>        unset for [tag = 100:200] label tag
> 
> however, it can't be used with print and the do loop requires {} even
> for 1 instruction. so when (what i think as) the "natural way" for
> a gnuplot beginner is
> 
>     f(x) = 2 * x + 3
>     print for [ x = 0:20:2 ] x, f(x)
> 
> i have to write
> 
>     f(x) = 2 * x + 3
>     do for [ x = 0:20:2 ] {print x, f(x) }
> 
> is there an internal/conceptual reason for print to not work like the
> others instructions?
> 
> also: i would like to suggest adding some examples in the gnuplot help
> print section:
> 
>  Syntax:
>        print <expression> {, <expression>, ...}
> 
> to demonstrate that's it's easy to cast a num as string by using "".
> my update should be
> 
>  Syntax:
>        print <expression> {, <expression>, ...}
> 
>  Examples:
> 
>        # print some text data
>        print "hello world"
>        # print some numeric data
>        x=12
>        print 12,x
>        # print combined data (first element *must* be a string)
>        print "".x." was the result"
> 
> also: i would like to know if there is a way to choose the expression
> separator. so i can write
> 
>     print x, f(x), g(x)
> 
> instead of
> 
>     print "".x. ",".f(x). ",".g(x)
> 
> thanks for helping.
> regards,
> 
> -- 
> Marc Chantreux
> Direction du numérique de l'Université de Strasbourg
> Pôle de Calcul et Services Avancés à la Recherche (CESAR)
> http://annuaire.unistra.fr/p/20200
> 
> 
> _______________________________________________
> gnuplot-info mailing list
> [email protected]
> Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-info



_______________________________________________
gnuplot-info mailing list
[email protected]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-info