problem passing variable to gnuplot

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

problem passing variable to gnuplot

Ray Anderson-2

I am attempting to utilize some variables as arguments to
be passed to gnuplot. I get an error "undefined variable"
when I attempt this even though I know the variable is
defined and exists in the current scope.

example:
       
        octave:21> a=1;
        octave:22> b=2;
        octave:23> gset xrange [a:b];
         line 0: undefined variable: a
         
         
If I just put the number in the gnuplot command everything
works as I expect with no error:
       
        octave:24> gset xrange [1:2]
        octave:25>
       
        What  is the proper way to accomplish the passing of
        variable arguments to gnuplot?
       
(I am using octave 2.0.9 and gnuplot 3.6 beta)


Ray Anderson

[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: problem passing variable to gnuplot

Dirk Eddelbuettel-3

  Ray> If I just put the number in the gnuplot command everything works as I
  Ray> expect with no error:
  Ray>        
  Ray>         octave:24> gset xrange [1:2]
  Ray>       octave:25>
  Ray>
  Ray> What is the proper way to accomplish the passing of variable
  Ray> arguments to gnuplot?

You can use eval on the return from sprintf as in

        octave:1> eval(sprintf("gset xrange [%d:%d]", 2, 3))
        octave:2> plot((1:10))
                        (creates window with a straight line between 2 and 3
                         as selected by gset)

Regards, Dirk

--
[hidden email]                   According to the latest official figures,
http://rosebud.ml.org/~edd        43% of all statistics are totally worthless.