Having trouble with global array variables
Olumide
50295 at web.de
Sun Jul 6 19:29:19 CDT 2008
Ben Abbott wrote:
> The line "global position" should occur in the original script as well
> as in each function that uses it.
>
> To be safe, be sure to insert the line "global position" ahead of any
> line that uses the variable "position".
>
> I haven't tried to run your script, but I did insert the lines where
> they belong ... hopefully, I got it all right.
Unfortunately not. I've written the following short demo/test case to
illustrate the problem:
##############################################
data = [ 0,0,0; 256,0,0; 0,256,0; 256,256,0; 128,128,5 ];
function foo()
global data;
data
endfunction
foo(); # outputs data = [](0x0)
data # outputs full matrix
##############################################
As you can see the global matrix 'data' is not visible within foo() even
if global data added to foo ...
:(
More information about the Help-octave
mailing list