Re: Assignment problem
- To: mathgroup at smc.vnet.net
- Subject: [mg86246] Re: [mg86219] Assignment problem
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Fri, 7 Mar 2008 02:24:32 -0500 (EST)
- Reply-to: hanlonr at cox.net
ToExpression["q" <> ToString[#] <> "=0" & /@ Range[10]];
Names["q*"]
{q1,q10,q2,q3,q4,q5,q6,q7,q8,q9}
Verifying that they are all zero
ToExpression[%]
{0,0,0,0,0,0,0,0,0,0}
Bob Hanlon
---- Marco Gabiccini <m.gabiccini at ing.unipi.it> 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?
>
> Thanks,
>
> Marco
>
> Ing. Marco Gabiccini, PhD
> Assistant Professor of Applied Mechanics
> Dept. of Mechanical, Nuclear and Production Engineering
> University of Pisa
> Via Diotisalvi, 2, 56126 Pisa (PI) - Italy
> Phone: +39-050-836.676
> E-mail: m.gabiccini at ing.unipi.it
>
>