help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

"plot" within function def


From: Ted Harding
Subject: "plot" within function def
Date: Fri, 15 Nov 1996 16:56:10 +0000 (GMT)

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.                                    (address@hidden)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]