help-octave
[Top][All Lists]
Advanced

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

Re: global variables


From: Michal Studniarek
Subject: Re: global variables
Date: Tue, 21 Jan 2014 17:39:35 +0100

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.

Regards,
Michal


2014/1/21 Doug Stewart <address@hidden>



On Tue, Jan 21, 2014 at 9:32 AM, louis scott <address@hidden> wrote:
explains it, no you cannot.
"A global variable may only be initialized once in a global statement. "

So while you cannot change, you can set inside a function.


I think you are wrong.
You can can change its value in a function, otherwise why is it called a variable??


 
I admit, I never use them. I instead have a structure with state.

myvars.x = 22;
myvars.createfile = true;

myvars.madeitup_failure = makeitup(myvars, otherstuff);

function error_code = makeitup(statevars, otherstuff)
:
:


On Tue, Jan 21, 2014 at 2:16 PM, Jabcok <address@hidden> wrote:
Hello,

I would like to know if there is any possible way to change the value of global variable from the inside of the function in Octave?

Best regards.

Sławomir Jabłoński




_______________________________________________
Help-octave mailing list
address@hidden
https://mailman.cae.wisc.edu/listinfo/help-octave


_______________________________________________
Help-octave mailing list
address@hidden
https://mailman.cae.wisc.edu/listinfo/help-octave




--
DASCertificate for 206392


_______________________________________________
Help-octave mailing list
address@hidden
https://mailman.cae.wisc.edu/listinfo/help-octave



reply via email to

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