[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Newbie - Automatically Global variables
From: |
John W. Eaton |
Subject: |
Newbie - Automatically Global variables |
Date: |
Wed, 7 Sep 2011 12:19:34 -0400 |
On 7-Sep-2011, thombark wrote:
| i will need about 100 fixed values that I will use in many functions. They
| are mainly TRUE/FALSE variables but some are integers. I prefer not to use
| Global statements in each function, and I would like them to be protected.
| Is there a pre-processor?
| Can I define them as some form of built-in variables or reserved variables?
| I am only running on 1 PC so I don't mind extending the reserved variable
| list.
One solution is to put the global variables in a script file and call
that where it is needed. For example:
my_globals.m:
global foo;
global bar;
my_fun.m:
function [...] my_fun (...)
my_globals;
...
end
my_other_fun.m:
function [...] my_other_fun (...)
my_globals;
...
end
In recent versions of Octave, this should be relatively efficient
since the script file will be parsed and stored internally only once.
Older versions (prior to 3.0, I think) would parse and execute the
script file each time it was referenced.
jwe