Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: Assignment problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg86253] Re: Assignment problem
  • From: Szabolcs Horvát <szhorvat at gmail.com>
  • Date: Fri, 7 Mar 2008 02:25:52 -0500 (EST)
  • Organization: University of Bergen
  • References: <fqo8o1$suo$1@smc.vnet.net>

Marco Gabiccini wrote:
> Hi all,
> 
> I would like to do something like:
> 
> For[ i=1, i<n, i++, ToExpression[ "q" <> ToString[i] ] = 0 ]
> 
> that is assigning q1=0, q2=0, etc... but it does not work.
> 
> I would not like to use the easy way out:
> 
> For[ i=1, i<n, i++, q[i] = 0 ]
> 
> of employing q[i] instead of qi.
> 
> Can you help me please?

In[1]:= Table[ToExpression["q" <> ToString[i]], {i, 10}]
Out[1]= {q1, q2, q3, q4, q5, q6, q7, q8, q9, q10}

In[2]:= With[{q = #}, q = 0] & /@ %
Out[2]= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

Can you please explain your motivation for wanting to do this?


  • Prev by Date: Searching for multiple strings in a list
  • Next by Date: Re: Apply function to parts of a list
  • Previous by thread: Re: Assignment problem
  • Next by thread: Re: Assignment problem