MathGroup Archive 2008

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

Search the Archive

Re: Symbol function, a question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg90506] Re: Symbol function, a question
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Fri, 11 Jul 2008 02:03:36 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <g54om5$f1i$1@smc.vnet.net>

tung tran wrote:

> Firstly, I create a variable
> x95 = 100
> Now, I want to change the value of my variable x95 to 20 ,
> so I want to use some procedure like :
>  
> Symbol["x" <> ToString[95]] = 20
> my idea is to make Mathematica write the term "x95" automatically for
> me but when I use the Symbol function in this case, it gives me
> automatically 100 and I don' t know how to call only x95.

You may have to write your own function to achieve this. For instance,

     SetAttributes[mySet, HoldFirst]

     mySet[name_String, value_] :=
         ToExpression[name <> "=" <> ToString[value]]

     x95 =.
     mySet["x95", 100]
     mySet["x95", 20]
     mySet[#, 50] &["x" <> ToString[95]]
     Table[mySet[#, RandomInteger[]] &["x" <> ToString[n]], {n, 5}]

     100

     20

     50

     {0, 0, 1, 0, 1}


Regards,
-- Jean-Marc


  • Prev by Date: Help with "If" statement within "Table"
  • Next by Date: Re: Re: Question about diference between Animate and
  • Previous by thread: Re: Symbol function, a question
  • Next by thread: Re: Symbol function, a question