initializing user defined handles in GUIDE GUI

조회 수: 2 (최근 30일)
hana
hana 2012년 7월 17일
Do you have to initialize user defined handles in OpeningFcn of GUIDE gui or it's enough to declare them in any of the callbacks. which one is a better practice and why?
thanks

채택된 답변

Walter Roberson
Walter Roberson 2012년 7월 17일
Initialize them anywhere that a reasonable programmer could find them easily enough. The more obscure you make using them in your deepest dankest code, the more attention you have to give to ensuring that there is a clean interface to that obscurity.
Remember, once created, other portions of your code may need access to the handles. If you are stashing them in the handles structure, be sure to guidata() the new handles structure into place.
GUIDE promotes the idea of creating all you figures and UI ahead of time and leaving it existing, but possibly making it invisible. That is one approach. I personally tend to prefer to create and destroy my UI components at need.
One thing I found through experience is that any time I had code that acted differently depending on whether a particular UI component existed or not (e.g., ishandle()), that chances were good that sooner or later the meaning of having that component exist would drift, leading to situations where testing the handle would no longer be correct.
For example, if I test whether guidata.statsfigure is a handle in order to decide whether a statistical analysis is currently underway, then eventually that statsfigure will need to exist for another reason (even as simple as the user asked to leave it up while running the next step), and the state implied by the existence or not of the object would get out of whack. Better, I found, to have explicit state variables rather than relying on a presentation object's existence to encode state.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by