Updated 12 Jan 2004
This is another modified version of the original KEEP M-file by Xiaoning (David) Yang (1998). It allows the user to specify some variables and clear the rest, and uses the same syntax as the clear command. The main contribution of this code is that it allows the use of the wildcard * in exactly the same fashion as the clear command.
keep3 var1 var2
Clears all variables expect var1 and var2
Clears all variables expect those whose names begin with 'va' and end with '2'.
Requires Matlab 6.5 (R13) because it makes use of the regexp command.
Martin Barugel (2023). KEEP3 (https://www.mathworks.com/matlabcentral/fileexchange/4259-keep3), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Fixed a bug that caused KEEP3 to clear all variables when there where no variables to clear. It now works just fine.