Re: String as a variable name
- To: mathgroup at smc.vnet.net
- Subject: [mg100277] Re: String as a variable name
- From: "A. B." <functionalcoatings at gmail.com>
- Date: Sun, 31 May 2009 06:31:40 -0400 (EDT)
I found it: I forgot to wrap Evaluate around the assignment. This works: Symbol["variable"<>"1"]//Evaluate=10 Many thanks. A.B. > In a data analysis package I use often, a facility is provided for > substituting a string for the name of a variable. Quoting from the user > manual: > > "String Substitution Using $: > Wherever Igor expects the literal name of an operand, such as the name of a > wave, you can instead provide a string expression preceded by the $ character. > The $ character tells Igor to evaluate the string expression and substitute > that value as the name it expected." > > For example, I can write: > VariableName="variable"+"1" > $variableName=10, > > the variable whose name is variable1 would then be assigned the value 10. > > I was looking for an equivalent in Mathematica. I tried looking into the > Symbol function, but haven't found a way to use it for this purpose. Thus, > something like: > > Symbol["variable"<>"1"]=10 > > does not work. > > I sometimes need to create variables during the execution of a program whose > names are made up from concatenated strings and I need to be able to assign > values to them. > > Any idea ? > > A.B.