variable: global or in guidata
조회 수: 2 (최근 30일)
이전 댓글 표시
which is more useful in gui programming, to save the variable in handles structure or to make it global to have access on it?
댓글 수: 0
채택된 답변
Daniel Shub
2011년 11월 17일
I would suggest you avoid global variables. They are more powerful than what you need, and therefore probably not the best choice. The FAQ has a couple of suggestions:
댓글 수: 0
추가 답변 (2개)
Alex
2011년 11월 17일
Global variables are often a bad choice when programming.
Another option for sharing data through a gui is basing the gui in a class. This is my preferred method.
댓글 수: 0
Jan
2011년 11월 17일
In case of problems it is hard to find the code, which is responsible for the last changes in the global variables. In addition the uasge of globals lead to problems, if you want to open multiple instances of the GUI.
Therefore I prefer guidata - which calls setappdata internally, so you can call it directly also. Using the figure's UserData is equivalent. For conventional reasons I use the UserData for static values as handles and the application data for dynamic values like the current choice of variables etc. But this is a question of taste.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Whos에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!