2
$\begingroup$

I would like to create Manipulate which look like this

n = 4; Manipulate[{a, b, c}, {a, Range[n]}, {b, Range[n]}, {c, Range[n]}] 

but wherein list of controls defined dynamically. I tried this code, which does not work

vars = {a, b, c}; Manipulate[vars, Table[{vars[[i]], Range[n]}, {i, 1, vars // Length}]] 
$\endgroup$

2 Answers 2

1
$\begingroup$

You need to tell Manipulate to Evaluate the expression generating the controls before the rest. Also you have to convert the single List generated by Table into a sequence of lists, each one specifying a single controller. For example with:

vars = {a, b, c}; n = 4; Manipulate[ Evaluate@vars, Evaluate[ Sequence @@ Table[{vars[[i]], Range[n]}, {i, 1, vars // Length}] ] ] 
$\endgroup$
5
$\begingroup$

Generalizing to a variable number of controls and variable range of controls.

maxNbrControls = 10; maxRngControls = 10; Manipulate[ Manipulate[ Evaluate[ a /@ Range[nbrControls]], Evaluate[ Sequence @@ ({{a[#], 1, Subscript[a, #]}, Range[rngControls], ControlType -> SetterBar} & /@ Range[nbrControls])]], Row[{ Control[{{nbrControls, 3, "Number of\nControls"}, Range[maxNbrControls]}], Spacer[25], Control[{{rngControls, 4, "Range of\nControls"}, Range[maxRngControls]}]}]] 

enter image description here

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.