From help-octave-request at bevo dot che dot wisc dot edu Fri Jan 25 04:05:59 2002 Subject: Re: Recursion / global variables trouble From: Pieter Thysebaert To: help-octave at bevo dot che dot wisc dot edu Date: Fri, 25 Jan 2002 10:06:43 +0100 On Friday 25 January 2002 09:39, Pieter Thysebaert wrote: > function r=forloop(z,depth) > global iterationvars; %vector that holds the variable values > global N; > global Q; > > if (depth==N) > r = calc_term_in_function_of_iteration_vars(z); > else > for iterationvars(depth)=0:Q-sum(iterationvars(1:depth-1)) > %for x1, where depth = 1, sum(iterationvars(1:0)) will return > 0=OK %DEBUG printf > printf("Value of x%d is %d\n\r",depth,iterationvars(depth)); > r = r+forloop(z,depth+1); > endfor > endif > endfunction .... > So somehow iterationvars(depth) is not adjusted properly (in the > for...line) Can anybody help me with this parameter passing /global > variable issue ? I helped myself; instead of adjusting the global var iterationvars in the for... line, I inserted an auxiliary variable: for x= 0:Q-sum(iterationvars(1:depth-1)) iterationvars(depth) = x; %continue as before and it works now! (But I still don't know why the original form didn't) Pieter ------------------------------------------------------- ------------------------------------------------------------- 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 -------------------------------------------------------------