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:

Manipulate[Map[Symbol[#]&,myVariables],Grid[{Map[Control[{Symbol[#],0,1}]&, myVariables]}]]
  • $\begingroup$ 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 $\endgroup$ – Lukas Lang Apr 20 '18 at 15:38
  • $\begingroup$ @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. $\endgroup$ – LBogaardt Apr 20 '18 at 16:13

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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.