Re: Modify variable names in a loop
- To: mathgroup at smc.vnet.net
 - Subject: [mg101780] Re: [mg101744] Modify variable names in a loop
 - From: Adriano Pascoletti <adriano.pascoletti at dimi.uniud.it>
 - Date: Fri, 17 Jul 2009 05:01:38 -0400 (EDT)
 - References: <200907161215.IAA02231@smc.vnet.net>
 
The string "output" <> ToString[Evaluate[kk]] can be transformed into a
Symbol by means of Evaluate[toExpression["output" <>
ToString[Evaluate[kk]]]]:
In[1]:= For[kk = 1, kk <= 3, kk++,
     Evaluate[ToExpression[StringJoin["output",
             ToString[Evaluate[kk]]]]] = {kk, kk + 1, kk + 2}];
  {output1, output2, output3}
Out[1]= {{1, 2, 3}, {2, 3, 4}, {3, 4, 5}}
Adriano Pascoletti
2009/7/16 Parita <parita.patel at gmail.com>
> Hi
>
> I would like to modify the variable name in a loop and assign values
> to the variable.
>
> For[kk = 1, kk <= 3, kk++,
>    "output" <> ToString[Evaluate[kk]] = {kk,kk+1,kk+2};
> ];
>
> I would like the following output
> output1={1,2,3}
> output2={2,3,4}
> output3={3,4,5}
>
> Although, "output" <> ToString[Evaluate[kk]] evaluates as expected, it
> does not let me assign values. Am I missing something here?
>
> Thanks in advance for your help
>
>
- References:
- Modify variable names in a loop
- From: Parita <parita.patel@gmail.com>
 
 
 - Modify variable names in a loop