Global variables in functions
24 views (last 30 days)
I have been trying to use global variables so I can make changes to the said variable in different functions but I can't seem to do it. It seems like the second function does not work. Please help.
Image Analyst on 11 Sep 2017
Edited: Image Analyst on 11 Sep 2017
Get rid of the "clear global" function in new1(), which blew away your existing globals, and add "global m" to eat():
And the variables are only global for the functions that actually have the "global m" line in them, not to other functions that don't have that line.
See the FAQ on globals: http://matlab.wikia.com/wiki/FAQ#Are_global_variables_bad.3F
More Answers (2)
dpb on 11 Sep 2017
>> help clear
| clear GLOBAL removes all global variables.
However, using global is not recommended as a general programming practice; you don't show enough context to see why there's any reason should be using one here so I'd suggest not doing so.
Raja Awais Liaqait on 7 Oct 2019
I want help in the following code.
global min_realvar ;
global max_realvar ;
Firstly, I want to get the value of these variables and secondly i want to write them in such away that I can give the values of these variables as an input.