help-octave
[Top][All Lists]
Advanced

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

Re: global variables


From: Mike Miller
Subject: Re: global variables
Date: Tue, 21 Jan 2014 11:50:54 -0500

On Tue, Jan 21, 2014 at 17:39:35 +0100, Michal Studniarek wrote:
>
> I think the question was if you can define a global variable then change
> its value inside function and to have a new value available outside.
>
> In example:
>
> global x=2;
>
> function x=test()
>  global x;
>  x=4;
> endfunction
>
> Value of global variable x will be still 2. Function operates on global var x
> locally but can not change its value globaly.

In fact your example is almost exactly out of the manual and shows
that a function can indeed modify the value of a global variable, both
inside and outside the scope of the function.

See https://www.gnu.org/software/octave/doc/interpreter/Global-Variables.html

-- 
mike


reply via email to

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