2
$\begingroup$

With the following code:

x[1] = 0;
Checkbox[Dynamic[x[1]], {0, 1}]
Dynamic[x[1]]

I can create the dynamic variable x[1] and it works as intended. How can I create several dynamic variables at once? I tried:

Table[x[i] = 0; {Checkbox[Dynamic[x[i]], {0, 1}], Dynamic[x[1]]}, {i, 1, 16}]

But it doesn't work. Somehow, it creates only one variable and all checkboxes work in a non independent way.

$\endgroup$

1 Answer 1

4
$\begingroup$

Edit

With initialization:

Clear["Global`*"]
Array[Dynamic[x[#], Initialization :> (x[_] := 0)] &, 10]
Table[Checkbox[dynamic[x[i]], {0, 1}], {i, 1, 10}] /. 
 dynamic :> Dynamic

Original

Clear["Global`*"]
Dynamic[Table[x[i], {i, 1, 10}]]
Table[Checkbox[dynamic[x[i]], {0, 1}], {i, 1, 10}] /. 
 dynamic :> Dynamic
$\endgroup$
2
  • $\begingroup$ Something odd happens: If I write Evaluate[Dynamic[Table[x[i] = 0, {i, 1, n}]]] and suppress the output, it no longer assign values to the x[i]. Any idea why that happens? $\endgroup$
    – Red Banana
    Sep 18, 2022 at 6:24
  • 3
    $\begingroup$ Dynamic represents a spot on the screen as @Nasser pointed out in 267608. You can click on the checkbox and manually evaluate the corresponding x[i] to see that it is updating values, although since you have suppressed the output, the dynamic display of the table is not there anymore. $\endgroup$
    – Syed
    Sep 18, 2022 at 6:32

Your Answer

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

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