Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to clear all variables except one or two
Date: Sun, 1 Feb 2009 22:57:01 +0000 (UTC)
Organization: Universit&#228;t Heidelberg
Lines: 10
Message-ID: <gm59bt$k6p$1@fred.mathworks.com>
References: <gm2nh1$4hu$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1233529021 20697 172.30.248.37 (1 Feb 2009 22:57:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 1 Feb 2009 22:57:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869888
Xref: news.mathworks.com comp.soft-sys.matlab:515293


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