Is it possible to visualize/edit a big matrix as a table ? I often end up exporting/copying big tables to Excel for seeing them, but I would prefer to stay in Mathematica and have a similar view as in Excel. Note that I'm looking for a non commercial solution. Thanks
Answer
Based on the approach of F'x this is a version aimed rather at large arrays. It should perform reasonably well independent of the array size and lets one edit the given variable directly. Performance suffers only from the maximal number of rows and columns to be shown, which can be controlled with the second argument. I did choose to use the "usual" syntax for controllers with a Dynamic
wrapper, which basically just serves as a Hold
in the function definition pattern. With the Interpretation-wrapper it will evaluate to just the array it shows. There are a lot of possible improvements, so everyone is welcome to make such improvements. Here is the code:
editMatrix[Dynamic[m_], maxfields_: {10, 10}] :=
With[{maxrows = Min[maxfields[[1]], Length[m]],
maxcols =
If[(Depth[m] - 1) == 2, Min[maxfields[[2]], Length[m[[1]]]], 1]},
Interpretation[
Panel[DynamicModule[{rowoffset = 0, coloffset = 0},
Grid[{{If[Length@m > maxrows,
VerticalSlider[
Dynamic[rowoffset], {Length[m] - maxrows, 0, 1}]],
Grid[Table[
With[{x = i, y = j},
Switch[{i, j}, {0, 0}, Spacer[0], {0, _},
Dynamic[y + coloffset], {_, 0},
Dynamic[x + rowoffset], _,
If[(Depth[m] - 1) == 2,
InputField[Dynamic[m[[x + rowoffset, y + coloffset]
]
],
FieldSize -> 5],
InputField[Dynamic[m[[x + rowoffset]]], FieldSize -> 5]
]
]
],
{i, 0, maxrows}, {j, 0, maxcols}]]}, {Spacer[0],
If[Length@First@m > maxcols,
Slider[Dynamic[coloffset], {0, Length[m[[1]]] - maxcols,
1}]
]}}]
]
],
m]
];
You can test it with, e.g.:
a = RandomReal[1, {1000, 300}];
editMatrix[Dynamic[a], {10, 6}]
This will confirm that a
will actually be changed when editing the corresponding InputField
:
Dynamic[a[[1, 1]]]
Comments
Post a Comment