Can I declare global handles and/or variables?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Can I declare global handles? Variables?
0 commentaires
Réponse acceptée
Bjorn Gustavsson
le 6 Juin 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 commentaires
Plus de réponses (1)
Jan
le 6 Juin 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 commentaires
Voir également
Catégories
En savoir plus sur Debugging and Analysis dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!