"plot" within function def

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

"plot" within function def

Ted.Harding
Hi Folks,

Octave 1.1.1

I don't know if this is a bug: I can only describe the behaviour.
The following is a file: call it "test.m"; its purpose is to define a
function "config".

In real life, "config" computes 8 numbers x1r,x1s,x2r,x2s,y1r,y1s,y2r,y2s
and plots two triangles, each with one corner at the origin, with the
other four points at coordinates given by these numbers. The "config"
following simply assigns values to these numbers for the sake of showing
what's going on.

=-=-=-= file "test.m" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
1;

# plot([0 1],[0 1])

function config()

x1r =  0.99622  ; x2r = 0.96534 ; x1s = -0.72938 ; x2s = -0.91033 ;
y1r = -0.086811 ; y2r = 0.26098 ; y1s =  0.68411 ; y2s =  0.41387 ;

plot([0;x1r;x2r;0],[0;y1r;y2r;0],"-b",[0;x1s;x2s;0],[0;y1s;y2s;0],"-g")

endfunction
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Now for the fun bit.

1. Start octave from scratch.
2. Do "test" to read in the above file.
3. Do "config".
      You will see ONLY ONE TRIANGLE (the first).
4. Do "config" again.
      You will now see TWO TRIANGLES, as intended. And the same for every
      repetition.
5. Quit octave.

Next, edit "test.m" so as to uncomment the line "plot([0 1],[0 1])".
Then repeat the above. NOW YOU WILL SEE TWO TRIANGLES FIRST TIME, as
intended.

It therefore seems that the "plot" command, when it occurs inside a
function definition as above, must first be "primed" by being executed
before the the function is called.

There it is: any comments?

Best wishes,
Ted.                                    ([hidden email])

Reply | Threaded
Open this post in threaded view
|

"plot" within function def

John W. Eaton-6
On 15-Nov-1996, Ted Harding <[hidden email]> wrote:

: I don't know if this is a bug: I can only describe the behaviour.
: The following is a file: call it "test.m"; its purpose is to define a
: function "config".

It is probably a bug in something, but I'm not sure what.

: Now for the fun bit.
:
: 1. Start octave from scratch.
: 2. Do "test" to read in the above file.
: 3. Do "config".
:       You will see ONLY ONE TRIANGLE (the first).
: 4. Do "config" again.
:       You will now see TWO TRIANGLES, as intended. And the same for every
:       repetition.
: 5. Quit octave.
:
: Next, edit "test.m" so as to uncomment the line "plot([0 1],[0 1])".
: Then repeat the above. NOW YOU WILL SEE TWO TRIANGLES FIRST TIME, as
: intended.
:
: It therefore seems that the "plot" command, when it occurs inside a
: function definition as above, must first be "primed" by being executed
: before the the function is called.
:
: There it is: any comments?

I was able to observe this behavior, but I got inconsistent results.
After poking around for a while, it seems that the strings that are
sent to the plotter stream are ok, and that they are being flushed, so
I don't know why the display is not always updated.

Anyway, here is a patch that seems to work around the problem,
whatever it really is.

*** scripts/plot/plot_int.m~ Sun Oct  8 23:26:11 1995
--- scripts/plot/plot_int.m Fri Nov 15 18:24:40 1996
***************
*** 81,86 ****
--- 81,88 ----
        endif
        endif
 
+       replot;
+
      unwind_protect_cleanup
 
        if (! hold_state)


Hmm,

jwe