Re: How can I use multiple filename ?

• To: mathgroup at smc.vnet.net
• Subject: [mg67022] Re: How can I use multiple filename ?
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Wed, 7 Jun 2006 05:09:38 -0400 (EDT)
• Organization: The Open University, Milton Keynes, UK
• References: <e63mff\$knj\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```bar at ANTYSPAM.ap.krakow.pl wrote:
> Hi ,
>  When I try :
> For[i=1,i<10,
>     name="a"<>ToString[i];
>     i>>name;
>     i++];
>
> it doesn'w work
>
> Could  You help me ?
>

It works indeed; although not in the way you may have expected: the
symbol "name" is not evaluated to its value; therefore Mathematica
writes in a file called "name" rather than "a1", or "a2", etc.

In[1]:=
For[i = 1, i < 10, name = StringJoin["a", ToString[i]]; i >> "name"; i++];

In[2]:=
!!a1

From In[2]:=
General::noopen :  Cannot open a1. More...

In[3]:=
!!name

From In[3]:=
9

The following expressions will do what you want.

In[4]:=
Clear[a, b, c]

In[5]:=
For[i = 1, i < 10, name = StringJoin["a", ToString[i]];
Put[i + a, Evaluate[name]]; i++];

In[6]:=
!!a1

From In[6]:=
1 + a

In[7]:=
For[i = 1, i < 10, Put[i + b, Evaluate[StringJoin["a", ToString[i]]]];
i++];

In[8]:=
!!a5

From In[8]:=
5 + b

This one is even more C-like:

In[9]:=
For[i = 1, i < 10, Put[i + c, Evaluate[StringJoin["a", ToString[i++]]]]; ];

In[10]:=
!!a9

From In[10]:=
9 + c

Best regards,
Jean-Marc

```

• Prev by Date: Re: How can I use multiple filename ?
• Next by Date: matrix substitution
• Previous by thread: Re: Re: How can I use multiple filename ?
• Next by thread: Plot Sequencies of Complex Functions