String as a variable name
- To: mathgroup at smc.vnet.net
- Subject: [mg100276] String as a variable name
- From: "A. B." <functionalcoatings at gmail.com>
- Date: Sun, 31 May 2009 06:31:28 -0400 (EDT)
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.