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
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
> 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
"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.
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.