help-octave
[Top][All Lists]
Advanced

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

Re: global variables


From: Jose
Subject: Re: global variables
Date: Tue, 21 Jan 2014 18:50:08 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0

On 21/01/14 18:39, 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.

Hummm... It will not after you execute the test script. Have a look:

---->
octave:1> global x=2;
octave:2>
octave:2> function x=test()
>  global x;
>  x=4;
> endfunction
octave:3> x
x =  2
octave:4> test;
octave:5> x
x =  4
<----

BR,
J.


reply via email to

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