How can I add a required step before a built-in function runs after calling it?
1 view (last 30 days)
Show older comments
For example, sometimes in a stupor I type in 'clear' and press enter when I mean to type in 'clear x' and press enter. Is there anyway I can require an extra keyboard input after using 'clear' to prevent accidentally clearing all variables? I would like to be prompted by 'Press 'y' if you want to clear all variables.' Is this possible?
0 Comments
Accepted Answer
the cyclist
on 21 Jun 2015
I think the simplest way to do this would be to make a function called myclear, which behaves the way you want. For example, it could first check whether you called it with arguments, check with you, then call the MATLAB clear command.
You could use the nice keep function from the File Exchange as a model for how to construct the exact behavior you want.
2 Comments
Image Analyst
on 21 Jun 2015
No need for the File Exchange keep function with recent versions of MATLAB:
clearvars variables -except keepVariables
removes the variables specified by variables, and does not
remove the variables specified by keepVariables. This syntax
allows you to use a combination of variable names, wild card
characters, or regular expressions to specify variables to remove
or keep.
More Answers (0)
See Also
Categories
Find more on Workspace Variables and MAT-Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!