Global variables in functions
9 visualizaciones (últimos 30 días)
farheen asdf el 11 de Sept. de 2017
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 el 11 de Sept. de 2017
Editada: Image Analyst el 11 de Sept. de 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
Más respuestas (2)
dpb el 11 de Sept. de 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 el 7 de Oct. de 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.