From help-octave-request at bevo dot che dot wisc dot edu Wed Dec 24 17:38:03 2003 Subject: Re: Globally global variables From: taltman at lbl dot gov To: Joe Koski cc: help-octave at bevo dot che dot wisc dot edu Date: Wed, 24 Dec 2003 23:36:28 +0000 (UTC) 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 -------------------------------------------------------------