Clear all workspace except variables use in GUI
Show older comments
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 Comments
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
on 19 Jul 2016
Accepted Answer
More Answers (0)
Categories
Find more on Whos in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!