0
$\begingroup$

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]}]]
$\endgroup$
2
  • $\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, 2018 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, 2018 at 16:13

1 Answer 1

0
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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