Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Clear all except some?

Subject: Clear all except some?

From: Aino

Date: 13 Aug, 2010 16:53:04

Message: 1 of 4

Hi all,

how can I clear all the variables in my Workspace except some chosen ones?

Thanks,
Aino

Subject: Clear all except some?

From: Sean

Date: 13 Aug, 2010 17:04:05

Message: 2 of 4

"Aino" <aino.tietavainen@removeThis.helsinki.fi> wrote in message <i43t9g$35k$1@fred.mathworks.com>...
> Hi all,
>
> how can I clear all the variables in my Workspace except some chosen ones?
>
> Thanks,
> Aino

clear variables you do not want
or find keep (et al) on the FEX. It's a very useful function to have.

Subject: Clear all except some?

From: Tom Bryan

Date: 13 Aug, 2010 18:23:02

Message: 3 of 4

On 8/13/10 12:53 PM, Aino wrote:
> Hi all,
>
> how can I clear all the variables in my Workspace except some chosen ones?
>
> Thanks,
> Aino

Use

   clearvars -except ...

Here's an example:

 >> a=1;b=2;c=3;d=4;e=5;f=6;
 >> whos
   Name Size Bytes Class Attributes

   a 1x1 8 double
   b 1x1 8 double
   c 1x1 8 double
   d 1x1 8 double
   e 1x1 8 double
   f 1x1 8 double

 >> clearvars -except c f
 >> whos
   Name Size Bytes Class Attributes

   c 1x1 8 double
   f 1x1 8 double

Here's the reference page:
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/clearvars.html

Best wishes,
Tom

Subject: Clear all except some?

From: Aino

Date: 14 Aug, 2010 11:42:04

Message: 4 of 4

Thank you all!

-Aino

Tom Bryan <tom.bryan@mathworks.com> wrote in message <i442i6$sh4$1@fred.mathworks.com>...
> On 8/13/10 12:53 PM, Aino wrote:
> > Hi all,
> >
> > how can I clear all the variables in my Workspace except some chosen ones?
> >
> > Thanks,
> > Aino
>
> Use
>
> clearvars -except ...
>
> Here's an example:
>
> >> a=1;b=2;c=3;d=4;e=5;f=6;
> >> whos
> Name Size Bytes Class Attributes
>
> a 1x1 8 double
> b 1x1 8 double
> c 1x1 8 double
> d 1x1 8 double
> e 1x1 8 double
> f 1x1 8 double
>
> >> clearvars -except c f
> >> whos
> Name Size Bytes Class Attributes
>
> c 1x1 8 double
> f 1x1 8 double
>
> Here's the reference page:
> http://www.mathworks.com/access/helpdesk/help/techdoc/ref/clearvars.html
>
> Best wishes,
> Tom

Tags for this Thread

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.

Contact us