From help-octave-request at bevo dot che dot wisc dot edu Mon Oct 4 08:56:04 1999 Subject: Re: Generating global variables locally From: Daniel Heiserer To: viveks at me dot iitb dot ernet dot in CC: help-octave at bevo dot che dot wisc dot edu Date: Mon, 04 Oct 1999 15:55:12 +0200 viveks at me dot iitb dot ernet dot in wrote: > > Hello: > > I am not sure whether I am going to ask a stupid question. Is it possible > to generate, from within a function, a large number of global variables > and assigning values to them? And, it should also be possible to destroy > those global names as and when required by calling a similar function. > > For example: > > --------------------------- > function generate_global_vars(a_vector) > # a_vector is a vector whose size is unknown. > > for val = ext > > # Here I want to generate global variables > # and assign values to them. The names and number of these global variables > # will be different based on the size and the value of the vector. For > # example, for a_vector = [10:5:30], I would like to create new global > # variables y10, y15, y20, etc. > > endfor > > endfunction Hmmm. Good question. >> global a=rand(4) works but doesnt do what I suspect. Try: >> global blubber=rand(3); ===================== function test(c) b=rand(c); global b; whos ===================== >> test(5) The whos in test.m should show blubber as I expect, but it doesn't. Also I would expect to have a "b" in my workspace after executing test(5), but I haven't. Any comments???? daniel --------------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. To ensure that development continues, see www.che.wisc.edu/octave/giftform.html Instructions for unsubscribing: www.che.wisc.edu/octave/archive.html ---------------------------------------------------------------------