4.94737

4.9 | 38 ratings Rate this file 146 downloads (last 30 days) File Size: 1.83 KB File ID: #181

keep

by David Yang

 

10 Aug 1999

No BSD License  

KEEP is complementary to the "clear" command: it keeps the supplied variables and deletes the rest.

Editor's Notes:

This file was a File Exchange Pick of the Week.

Download Now | Watch this File

File Information
Description

KEEP is complementary to the "clear" command: instead of clearing the supplied variables, it keeps them and deletes the rest.

For example, the command " keep x y " clears all variables from the workspace except x and y.

Acknowledgements
This submission has inspired the following:
KEEP3, keep2, Keep4, keepfield
MATLAB release MATLAB 5.2 (R10)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (40)
28 May 2002 Suresh Joel

Cool function - simple and useful

14 Jun 2002 Matt Remigy

Thanks !

26 Jun 2003 Till Bockemuehl

Nifty function. Exactly what I was searching for.

25 Sep 2003 Rasmus Anthin

Superb! I think it is obvious there should be a reciprocal to the clear function like this in matlab's inherent set of functions.

07 Oct 2003 B. Peña

thanks

19 Feb 2004 Fahad Mahmood

Smart function indeed! Good thing for us that you thought about it!

03 Jun 2004 Yaser Ahmed  
16 Sep 2004 Ilker Delice

Thanks a lot excellent work

03 Jan 2005 joep van berkel

great !!

17 Feb 2005 Athanasios Pechlivanis

You are great!!

Thanks a lot, you have saved much of my time!!

02 May 2005 Camilo Cano

Just wonderful. Works like a charm. Thanks a lot.

10 Jun 2005 Hui Shi

yes, that's exactly what I am looking for.
Thanks!

29 Jun 2005 Yi Li

Good job!

01 Aug 2005 D. Gietelink

Perfect! why is this not a standard matlab function yet?

03 Jan 2006 Jerome G.

Exactement ce que je cherchais.

18 May 2006 Ivan Ordonez

It is a very good and practical tool.

05 Jun 2006 Benjamin Fenech  
16 Nov 2006 Kristofer Svensson  
29 Mar 2007 Andrew Lingg

Very nice for cleaning up memory while holding onto important results

11 Apr 2007 Daniel Vasques

I agree this should come with MATLAB.

24 May 2007 Christoph Ullrich

Super - saves lines and lines of clean codes...

16 Aug 2007 Taon Khuu

Excellent little function!!!

27 Sep 2007 Andre Crawford

This file saves lots of time and extra coding.

02 Oct 2007 Andrew Gee

This is gold

19 Nov 2007 Mauricio Fernandez

Muchas gracias por tu trabajo, good job.

25 Feb 2008 J J

Why on earth is this function not part of MATLAB to begin with??

28 Feb 2008 Sulabh Dhanuka

Though simple in idea, it is such a useful function. I have wished for something like this for so long. I agree, it makes no sense for this to be a part of Matlab.

20 Mar 2008 M M Dupin

Dear MATLAB developers, please listen to users and add this *extremely* useful function in the core of MATLAB. Plus, it has already been tested by us!

28 Mar 2008 Mark Thommy

A very helpful piece of code, just what I needed. Well done to the author!

09 Apr 2008 Cornelis P. Bogerd

Excellent

04 May 2008 Chris Andrews

I love having this script. Thank you for posting!

14 May 2008 H D

Does Mathworks need to pay a lot to make this function in the built-in lib?

08 Jul 2008 Matthew Rydzik

Perfect code, Thanks!

12 Jul 2008 Sushil Subramanian

Excellent tool! MATLAB should include this.

18 Sep 2008 K R

Brilliant! This is incredibly useful.

23 Sep 2008 Touko Pouko

Bravissimo!

08 Oct 2008 Kristyn Falkenstern

Thank you! this is great.

25 Jun 2009 Thomas Deneux

looks great, but the code can be much more simple!
for example,

function keep(varargin)

% variables to clear in a cell array
varlist = evalin('caller','who');
varlist = setdiff(varlist,varargin);

% make a string (separate the variable by a space)
[varlist{:,2}] = deal(' ');
varlist = varlist';
varstr = [varlist{:}];

% and clear!
evalin('caller',['clear ' varstr])

13 Aug 2009 Florian  
30 Sep 2009 shah

thanks

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
clear variables David Yang 22 Oct 2008 06:33:29
tools David Yang 22 Oct 2008 06:33:29
keep complementary David Yang 22 Oct 2008 06:33:29
utilities David Yang 22 Oct 2008 06:33:29
 

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