On global variables.
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Cruz Angel Echevarria
el 12 de Feb. de 2016
Comentada: Walter Roberson
el 12 de Feb. de 2016
Good morning Matlab users.
I would really appreciate some help on the following issue. I am working with a script file which calls a first function file which in turn calls a second function file. I have declared some variables as global. Both function files recognize all but one of these variables as global (blue color). However, the script file does not seem to recognize one particular variable as a global one. Please let me show you the first line of the code (which appears in the three files aforementioned).
global Numero C_C C_NC Saving_C Saving_NC N g_a I_Y n_bar S_bar n_mean r w ...
In particular, the variable causing the problem is the fourth one, "Saving_C". Does anyone have any idea of what I am doing wrong? Thanks in advance for your cooperation.
Regards,
Cruz
University of the Basque Country
3 comentarios
Stephen23
el 12 de Feb. de 2016
Editada: Stephen23
el 12 de Feb. de 2016
Globals come second on this list:
More discussion of why globals are terrible way to write code:
The official MATLAB documentation says "Use global variables sparingly, if at all.", and shows better ways to pass variables between workspaces (pass them as arguments!):
Walter Roberson
el 12 de Feb. de 2016
Does the same variable happen to occur as the name of a parameter to the function?
Respuestas (0)
Ver también
Categorías
Más información sobre Entering Commands en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!