MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Clearing selected variables

  • To: mathgroup at smc.vnet.net
  • Subject: [mg86630] Re: [mg86625] Clearing selected variables
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Sat, 15 Mar 2008 17:42:59 -0500 (EST)
  • Reply-to: hanlonr at cox.net

Create variables and make assignments

ToExpression[Table["x" <> ToString[n] <> " = 1", {n, 20}]];

exclusions = {"x5", "x9", "exclusions"};

Verifying that assignments have been made

ToExpression[Names["Global`*"]]

{{x5,x9,exclusions},n,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}

Clear all assignments except variables in exclusions

ToExpression[# <> "=." & /@ Complement[Names["Global`*"], exclusions]];

Verifying that appropriate assignments have been cleared

ToExpression[Names["Global`*"]]

{{x5,x9,exclusions},n,x1,x10,x11,x12,x13,x14,x15,x16,x17,x18,x19,x2,x20,x3,x4,\
1,x6,x7,x8,1}

Remove all variables except those in exclusions

ToExpression[
  "Remove[" <> # <> "]" & /@ Complement[Names["Global`*"], exclusions]];

verifying that appropriate variables have been removed

Names["Global`*"]

{exclusions,x5,x9}


Bob Hanlon

---- pradeep <pradeep at purdue.edu> wrote: 
> Hello All,
> is there a way i can selectively clear all but a few variables in
> mathematica?? i have a large number of variables and am iteratively
> running my entire notebook through a loop and want most variables except
> a few to get cleared between iterations..
> any help would be appreciated!
> 
> thanks!
> Pradeep
> Purdue University
> 



  • Prev by Date: Re: Substitute all known relations in result
  • Next by Date: Re: ordering of multivariate polynomial terms
  • Previous by thread: Re: Clearing selected variables
  • Next by thread: Re: Clearing selected variables