0

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.

Edmund
  • 42,267
  • 3
  • 51
  • 143

0 Answers0