Can I declare global handles and/or variables?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Can I declare global handles? Variables?
0 comentarios
Respuesta aceptada
Bjorn Gustavsson
el 6 de Jun. de 2011
Yes, you can. But really, really try to avoid it. See for example: http://matlab.wikia.com/wiki/FAQ, or search for discussions on the matlab newsgroup. In short globals make code tricky to debug because there is only one global namespace - meaning if you happen to have 2 groups of functions that happens to use the same variable name there will be one variable that will be set by functions from both groups _and_then_used == errors will be caused by functions that are completely unrelated to where it blows up.
A presonal note: I included rather rapidly a few globals in a number of functions in a toolbox I wrote ~15 years ago - it was a poor design choise, but I still haven't completely weeded them out.
So sit back, take a second glance at your problem and draw up a good clean design. I've heard people use globals for very large matrices, but then others have suggested class-definitions and other tricks, if this is your problem you could also look at memmapfile.
0 comentarios
Más respuestas (1)
Jan
el 6 de Jun. de 2011
Yes. Simply add this line to each function, which uses the global variables "handles":
global handles
The fact, that you've posted 3 threads concerning "handles" seems, like you are confused about this topic. It would be more efficient, if you explain, what you are trying to achieve.
0 comentarios
Ver también
Categorías
Más información sobre Debugging and Analysis 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!