4.66667

4.7 | 3 ratings Rate this file 119 downloads (last 30 days) File Size: 2.33 KB File ID: #7129

Keep4

by Mirko Hrovat

 

12 Mar 2005 (Updated 28 Aug 2006)

Code covered by BSD License  

Keeps the listed variables in the calling workspace with a command format similar to "clear"

Download Now | Watch this File

File Information
Description

This is another version of Keep, which allows a user to specify what variables are kept in the workspace of the calling routine. "Keep" compliments "Clear".

This version has been extended to match the command format of the "clear" command for clearing variables. Thus wildcards and regular expressions are allowed. The version also supports the "global" key word and Keep will not touch global variables unless the "global" key word is used.

Examples of supported formats:
keep var1 var2
keep var*
keep -regexp expr1
keep global
keep global var1
keep global -regexp expr1

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
keep, keep2, KEEP3

MATLAB release MATLAB 7.2 (R2006a)
Other requirements None
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
01 Apr 2006 Bo Gao

very nice job!!

08 Jun 2006 David the Dude

Useful function but there is a bug:

The function returns an error if only one workspace variable exists. To reproduce. Clear workspace initialize 1 variable X and run keep(X)

29 Aug 2006 Mirko Hrovat

Thanks to David for pointing out the bug when there are no variables to delete. This generated an unnecessary error message. Comments were also improved to delineate the examples more clearly.

05 May 2009 Martin  
Please login to add a comment or rating.
Updates
27 Jun 2006

Bug fix to avoid error message when argument list matches the entire workspace variable set. For this case there are no variables to be "cleared".

28 Jun 2006

Another bug fix which fixes the same issue as the prior bug fix but with global variables.

28 Aug 2006

Updated comments to improve code metrics.

Tag Activity for this File
Tag Applied By Date/Time
keep Mirko Hrovat 22 Oct 2008 07:43:15
clear Mirko Hrovat 22 Oct 2008 07:43:15
variable Mirko Hrovat 22 Oct 2008 07:43:15
wildcard Mirko Hrovat 22 Oct 2008 07:43:15
global Mirko Hrovat 22 Oct 2008 07:43:15
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com