Given a certain number n
, I want to define n
controls within Manipulate
with the correct variable labelling. Visually, I want something like
where, for example, the output panel is the sum of ci
's ($1\leq$i
$\leq $n
), that is, 1 if the checkbox is ticked and 0 otherwise.
Using Dynamic
and Table
I can get close to my goal with the following code
Manipulate[Sum[c1, {i, n}],
Control[{{n, 1}, 1, 10, 1, Appearance -> "Labeled"}],
Dynamic[Table[Control[{{c1, 0}, {1, 0}}], {i, n}] // Column]]
It becomes then a question of defining the variables within the Table
and Control
environment. I'm aware of this question, but unfortunately using Symbol
or ToExpression
within Control
didn't seem to work.
I'm ultimately asking two questions:
- How do I correctly introduce and relabel new variables depending on
n
, that is,c1, c2, ... , cn
? Maybe usingc[i]
instead? - If I manage the first, how can I then easily manage such variables for a given output function? For example, if I want to sum them,
Sum[ci,{i,n}]
wouldn't work, so I might need something likec[i]
orSymbol["c"<>ToString@i]
.
Any ideas?
PS - This is a follow-up question to this question. I realised this was trickier than I initially thought and decided to ask a question solely focused on variable definition.