Thread Subject: How to clear all variables except one or two

Subject: How to clear all variables except one or two

From: Diego Zegarra

Date: 31 Jan, 2009 23:40:17

Message: 1 of 7

I have a code that creates many variables and at each iteration I want to clear all the variables except for one or two. Is this possible without specifying clear A, clear B and so on for every variable?

I know clear all deletes them all but I need to keep one of them.

Thanks

Subject: How to clear all variables except one or two

From: Matt Fig

Date: 1 Feb, 2009 00:11:01

Message: 2 of 7

Do a search on the FEX for: keep





Ak6<k]eihkh*aca{dIppd#ldkak]lijq{{]u_kj]{{]{_^r]gp]U#e{{^qa

Subject: How to clear all variables except one or two

From: Diego Zegarra

Date: 1 Feb, 2009 00:37:01

Message: 3 of 7

Actually I found a way that can be done easily, this for anyone out there needing this info,

clearvars -except v1 v2 ... clears all variables except for those specified following the -except flag. Use the wildcard character '*' in a variable name to exclude variables that match a pattern from being cleared. clearvars -except X* clears all the variables in the current workspace, except for those that start with X, for instance.

Subject: How to clear all variables except one or two

From: Matt Fig

Date: 1 Feb, 2009 00:51:02

Message: 4 of 7

What version are you using? I don't have a clearvars command.




k{{_l{A{ueUpah6]ajhdjdqie{kk#^]qcga{p^#*{]{k]airIp]dkk_]<]l

Subject: How to clear all variables except one or two

From: Diego Zegarra

Date: 1 Feb, 2009 01:23:02

Message: 5 of 7

R2008a, I think it just came out starting this version.

Subject: How to clear all variables except one or two

From: Jan Simon

Date: 1 Feb, 2009 22:57:01

Message: 6 of 7

Dear Diego Zegarra!"

> I have a code that creates many variables and at each iteration I want to clear all the variables except for one or two. Is this possible without specifying clear A, clear B and so on for every variable?

Let the names of all variables, which should be cleared, start with a specific string, e.g.
"away_". Then "clear away_*" deletes them from memory.

By the way: clearing and recreation of variables is very time consuming. It could be more effective to use a cell instead of a cloud of variables.

Good luck, Jan Simon

Subject: How to clear all variables except one or two

From: Steven Lord

Date: 2 Feb, 2009 15:49:53

Message: 7 of 7


"Diego Zegarra" <diegozbb@gmail.com> wrote in message
news:gm2thm$mcb$1@fred.mathworks.com...
> R2008a, I think it just came out starting this version.

You're correct, CLEARVARS was introduced in release R2008a.

http://www.mathworks.com/access/helpdesk/help/techdoc/rn/brjk1q5-1.html

--
Steve Lord
slord@mathworks.com

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
clear all Diego Zegarra 31 Jan, 2009 18:40:26
rssFeed for this Thread
 

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