0
$\begingroup$

This question already has an answer here:

I need to make an InputField Grid change the values of a matrix variable without creating a ton of dummy variables. Minimal example follows as the actual matrix is much larger. This will be used in a UI.

m = {{1, 2}, {3, 4}};

However, the InputFields are not linked to the values of m when referenced with Indexed. The Grid that is produced has empty InputFields even though m has values.

Grid@
 Table[InputField[Dynamic[Indexed[m, {r, c}]], Number, FieldSize -> Tiny],
  Evaluate[Sequence @@ Transpose[{{r, c}, Dimensions[m]}]]]

Mathematica graphics

When entering values into the InputFields they simply disappear and have no effect on m. m stays with its original values.

Dynamic@m

I next tried to Part instead of Indexed which led to errors and still the values that are entered disappear.

Grid@
 Table[InputField[Dynamic[m[[r, c]]], Number, FieldSize -> Tiny],
  Evaluate[Sequence @@ Transpose[{{r, c}, Dimensions[m]}]]]

Mathematica graphics

How do I create an InputField Grid linked to a matrix variable? Other control combinations are welcome. The objective is a GUI to edit the matrix such that the edited matrix can be extracted and used.

$\endgroup$

marked as duplicate by m_goldberg, Community Mar 3 '17 at 1:08

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ Michael E2 gave an answer you can use here $\endgroup$ – m_goldberg Mar 3 '17 at 0:52
  • $\begingroup$ @m_goldberg Arrrhhhh!! The dreaded With. That has something to do with the hold attributes of both Table and Dynamic interacting, correct? $\endgroup$ – Edmund Mar 3 '17 at 0:55
  • $\begingroup$ It has to do with creating a control with a pure function and Mathematica's method for avoiding scoping conflicts in pure functions. See this answer $\endgroup$ – m_goldberg Mar 3 '17 at 8:45