From help-octave-request at bevo dot che dot wisc dot edu Wed Dec 24 20:08:12 2003 Subject: Re: Globally global variables From: Joe Koski To: CC: Date: Wed, 24 Dec 2003 19:07:27 -0700 Tomer, Thanks for the information, I'll take a look at the html pages. Apparently the other rule is that if you declare a variable global inside a .m routine, that variable can't also be listed on the function line of that routine. Just found that one out by trial and error. Joe Koski on 12/24/03 4:36 PM, taltman at lbl dot gov at taltman@lbl.gov wrote: > Hi Joe, > > The variables to the right of the function name are the return values > of the function. They must be assigned a value before the termination > of the M-file, otherwise an error is signaled. You can return multiple > values by putting more variables within brackets: > > function [ month, day, year ] = date () > ... > > Global variables can be defined within any scope (top-level, within a > M-file, etc. ), but any called function which wishes to access that > global variable must declare it locally. This is all described in the > Octave manual: > > http://www.octave.org/doc/octave_10.html#SEC67 > > So, you can do this (Octave 2.1.50) > > octave> global x > octave> x = 5 > x = 5 > octave> function new_val = increment_x () >> global x; >> x = x + 1; >> new_val = x; >> endfunction > octave> increment_x > ans = 6 > octave> increment_x > ans = 7 > octave> increment_x > ans = 8 > octave> > > Is anything else confusing? Trust me, as a quick search of the > help-octave archives will prove, I was very confused regarding > this as well. :-) > > ~Tomer > > > On Dec 24, 2003 at 12:23pm, Joe Koski wrote: > > jkoski >Date: Wed, 24 Dec 2003 12:23:31 -0700 > jkoski >From: Joe Koski > jkoski >To: help-octave at bevo dot che dot wisc dot edu > jkoski >Subject: Globally global variables > jkoski >Resent-Date: Wed, 24 Dec 2003 13:23:39 -0600 > jkoski >Resent-From: help-octave at bevo dot che dot wisc dot edu > jkoski > > jkoski >As a new octave user, one of the things confusing me is global > variables. 1) > jkoski >Functions have a return list in square brackets, that other functions > easily > jkoski >find. 2) The manual says that global variables must be declared in the > jkoski >function called, not in the calling program. So be it. > jkoski > > jkoski >To get my variables to appear at the top octave level, it appears that > I > jkoski >must declare the variables as global both at the top level and in the > octave > jkoski >.m function. Is this true? If it is, then what is the purpose of the > return > jkoski >list in square brackets to the right of the function name? > jkoski > > jkoski >Thanks. > jkoski > > jkoski >Joe Koski > jkoski > > jkoski > > jkoski > > jkoski >------------------------------------------------------------- > jkoski >Octave is freely available under the terms of the GNU GPL. > jkoski > > jkoski >Octave's home on the web: http://www.octave.org > jkoski >How to fund new projects: http://www.octave.org/funding.html > jkoski >Subscription information: http://www.octave.org/archive.html > jkoski >------------------------------------------------------------- > jkoski > > jkoski > > > > > ------------------------------------------------------------- > Octave is freely available under the terms of the GNU GPL. > > Octave's home on the web: http://www.octave.org > How to fund new projects: http://www.octave.org/funding.html > Subscription information: http://www.octave.org/archive.html > ------------------------------------------------------------- > ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------