Can I declare global handles and/or variables?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Can I declare global handles? Variables?
0 Kommentare
Akzeptierte Antwort
Bjorn Gustavsson
am 6 Jun. 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 Kommentare
Weitere Antworten (1)
Jan
am 6 Jun. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Debugging and Analysis finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!