0

How can I use a list of variable names within Symbol[] inside a Manipulate[], specifically using Control[]?

I assume the problem arises due to the HoldAll attribute of Manipulate, similar to here, but I fail to find the right solution.

The following Mathematica code illustrates the problem:

myVariables={"var1","var2"}
Map[Symbol[#]&,myVariables]
Manipulate[Map[Symbol[#]&,myVariables],Grid[{{Control[{var1,0,1}],Control[{var2,0,1}]}}]]
Map[Control[{Symbol[#],0,1}]&,myVariables]
Manipulate[Map[Symbol[#]&,myVariables],Grid[{Map[Control[{Symbol[#],0,1}]&, myVariables]}]]
Carl Woll
  • 130,679
  • 6
  • 243
  • 355
LBogaardt
  • 1,595
  • 1
  • 11
  • 21
  • What do you want to achieve with Symbol? It is designed to convert strings to symbols. Also, take a look at this, something similar should work for you – Lukas Lang Apr 20 '18 at 15:38
  • @Mathe172 I want the Symbols (or their names) used inside the Manipulate to be pre-defined in some List. I do not see anything useful in your link. – LBogaardt Apr 20 '18 at 16:13

1 Answers1

0

Let vList be your list of variables:

vList = {var1, var2};

(I don't see any reason to define the list using strings, but if you insist you could do vList = Symbol /@ {"var1", "var2"}). Then, you need to use With to inject things into a HoldAll object like Manipulate, so one possibility is:

With[{v=vList, controls = Grid[{Control[{#, 0, 1}]& /@ vList}]},
    Manipulate[v, controls]
]

enter image description here

Carl Woll
  • 130,679
  • 6
  • 243
  • 355