Clear all workspace except variables use in GUI
이전 댓글 표시
Hello,
I am here today because I am developing a GUI in which I use some global variables, and handles of objects of the GUI. One of my button launches a script in which I would like to clear all variable which could be related to this script, but without touching the others variables that MATLAB is using for the GUI (and the global variables I instanciated).
Do you think it is possible?
I thank you in advance for your help. Best regards.
댓글 수: 2
Mixing globals, scripts, and a GUI together is a recipe for buggy, hard-to-maintain code.
Globals are a not a good way to pass data between workspaces, because they are very difficult to keep track of when they change, making bugs likely and debugging very hard. Scripts are much loved by beginners, but any serious code need to use the independent workspaces that functions offer.
Why not take the opportunity to learn how to program robustly, e.g. by passing data between workspaces using one of the recommended methods (not globals!):
As Doug says "I have never seen MATLAB code where globals were the right thing to do":
"Beginners dive right in to globals because they think using them is easy. They are also easy to do wrong. ... I always end up teaching people to program by careful data management rather than relying on globals."
And scripts really should't be used for anything that will be used for more than ten minutes:
Mathieu
2016년 7월 19일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Whos에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!