help-octave
[Top][All Lists]
Advanced

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

Re: global variables


From: Bill Denney
Subject: Re: global variables
Date: Fri, 26 May 2006 08:03:10 -0400 (EDT)

On Fri, 26 May 2006, address@hidden wrote:

global DEGUB = 0;

then, some functions later..

... = func1(...)
   ... = func2(...)
      isglobal("DEBUG")
   (END func2)
(END func1)

the "isglobal("DEBUG")" statement will answer with 0.. should this not be 1 ? Or isn't it possible to get some function calls deeper the global variables?

Within any function that uses a global variable, you have to declare it global (so that it knows to look for it). To do this, you would want to do something like:

function y = f1 (x)
  global x1;
  if isempty (x1)
    x1 = 1;
  endif
  x1
endfunction

function y = f2 (x)
  global x1;
  if isempty (x1)
    x1 = 2;
  endif
  x1
endfunction

when running f2 after f1, you should see something like

x1 = 1

If you run f1 after f2, you should see something like

x1 = 2

Hope this helps,

Bill

--
"Judging from last week's garbage, he had almost finished his cloning
machine design.  I only notice a few linear math errors.  This design
would just create a hologram and a bad chile con carne recipe."
"Man, you sure know your garbage!" -- The Garbage Man and Dogbert



reply via email to

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