MathGroup Archive 2009

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

Search the Archive

Re: Assigning Values to Many Symbols at Once

  • To: mathgroup at smc.vnet.net
  • Subject: [mg101714] Re: [mg101699] Assigning Values to Many Symbols at Once
  • From: Jaebum Jung <jaebum at wolfram.com>
  • Date: Wed, 15 Jul 2009 07:08:46 -0400 (EDT)
  • References: <200907141200.IAA05959@smc.vnet.net>

Gregory Lypny wrote:
> Hello everyone,
>
> I can create a bunch of symbols on the fly using the Symbol command,  
> as in
>
> 	Table[Symbol["x" <> ToString[i]], {i, 5}]
>
> to get
>
> 	{x1,x2,x3,x4,x5}
>
> But how can I assign values to these all at once?
>
> Regards,
>
> 	Gregory
>
>   
You can do it with MapThread

 In[15]:= var=Table[Symbol["x"<>ToString[i]],{i,5}]
Out[15]= {x1,x2,x3,x4,x5}
In[16]:= MapThread[Set,{var,Range[5]}]
Out[16]= {1,2,3,4,5}
In[17]:= x2
Out[17]= 2

- Jay




  • Prev by Date: Re: CityData seems to be dead.
  • Next by Date: Re: Assigning Values to Many Symbols at Once
  • Previous by thread: Re: Assigning Values to Many Symbols at Once
  • Next by thread: Re: Assigning Values to Many Symbols at Once