help-octave
[Top][All Lists]
Advanced

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

global variable question


From: John W. Eaton
Subject: global variable question
Date: Mon, 8 Dec 2003 09:17:27 -0600

On  8-Dec-2003, Christoph Dalitz <address@hidden> wrote:

| I am having trouble with the use of global variables in Octave 2.1.35.

2.1.35 is old.  Why not use hte latest recommended version, 2.1.50?

|  (a) Subsequent initializations of global variables are ignored, eg.
| 
|       global n = 10;
|       global n = 100;  # has no effect
| 
|      This happens for instance when a script is called a second time
|      after it has been edited.

This is intentional.  Perhaps Octave should print a warning.

|  (b) It seems to be impossible to declare more than one variable global
|      per line, eg.
| 
|       global n = 500;
|       global r = 0.95;
| 
|       function y = f(p)
|         global r,n;
|         y = 1 - binomial_cdf(round(r*n),n,p);  # error: `n' undefined
|       endfunction

Write

  global r n

instead.  That is compatible with Matlab.

|      Actually I would not care, because with a second "global" statement for
|      the variable n the above example works.
| 
|      I wonder however, whether I am missing something, because the manual
|      explicitly gives examples of the form
| 
|       global c = 3, d, e = 5

The manual is out of date.

jwe



-------------------------------------------------------------
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
-------------------------------------------------------------



reply via email to

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