3
$\begingroup$

Is it possible to create a dynamically changing binary $n \times n$ matrix $A$, which appears to the user as a $n \times n$ matrix/table of checkboxes and the user can change the entries of $A$ by checking or unchecking these checkboxes? If yes, what would be the easiest way?

$\endgroup$
0

1 Answer 1

6
$\begingroup$

Modifying last example in Manipulate>Neat Examples (also the second example in this answer):

Manipulate[
  ArrayPlot[Take[data, n, n]], 
  {{data, RandomInteger[{0, 1}, {20, 20}]}, ControlType -> None}, 
  {{n, 5}, 1, 20, 1}, 
  Dynamic[
    Panel[Grid[Outer[Checkbox[Dynamic[data[[#1, #2]]], {0, 1}] &, Range[n], Range[n]]]]]]

enter image description here

$\endgroup$
3
  • $\begingroup$ Thank you. Suppose now I would like to use the chosen matrix in following calculations, how would I get further access to the chosen matrix? $\endgroup$
    – MthQ
    Jul 2, 2014 at 12:50
  • $\begingroup$ @Thomas, you can use Manipulate[ArrayPlot[mat=Take[data, n, n]],...] to hold the chosen matrix in global variable mat. $\endgroup$
    – kglr
    Jul 2, 2014 at 13:13
  • $\begingroup$ I am going to need the gist of this. Thank you @kglr $\endgroup$ May 19, 2020 at 19:34

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.