Can I declare global handles and/or variables?
3 次查看(过去 30 天)
显示 更早的评论
Can I declare global handles? Variables?
0 个评论
采纳的回答
Bjorn Gustavsson
2011-6-6
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 个评论
更多回答(1 个)
Jan
2011-6-6
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Debugging and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!