This question already has an answer here:

Given a MatrixPlot inside a Manipulate, say some $M(t)$ where $M_{ij}$ real for all entries, is there a way to show the values of each $M_{ij}$ inside matrix plot whilst the Manipulate runs?

marked as duplicate by Edmund, Henrik Schumacher, m_goldberg, LCarvalho, Öskå Nov 15 at 6:46

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.

  • Sorry all I might have been unclear, what I mean is, say, given the 2x2 rotation matrix {{cos a t, sin a t}{-sin a t, cos a t}}, how can one display their values as manipulate varies wrt a? – MKF Nov 10 at 13:45
  • This just being an example – MKF Nov 10 at 16:38
  • mathematica.stackexchange.com/questions/9884/… solved it! thanks! – MKF Nov 10 at 16:50

Update: Using the example matrix from the comments:

Manipulate[With[{mat = {{Cos[ a t], Sin [a t]}, {-Sin[ a t], Cos[ a t]}}}, 
    MatrixPlot[mat, Mesh -> All, ImageSize -> 1 -> 100, 
      Epilog -> Dynamic[MapIndexed[Text[Style[Round[#, .01], Large, 
       If[Abs[#] >= .5, White, Black]], {#2[[1]], 3 - #2[[2]]} - .5] &, mat, {2}]]]], 
   {{a, 1/2}, 0, 1}, {{t, 0}, -2 Pi, Pi}]

enter image description here

Original answer:

Using a Slider to change the dimensions of the matrix and EventHandler to increase (left mouse click) / decrease (right mouse click) values of matrix elements:

DynamicModule[{m = ConstantArray[0, {20, 20}]},
 Manipulate[mat = m[[;; n, ;; n]]; 
   Dynamic@EventHandler[
     MatrixPlot[mat, Mesh -> All, ImageSize -> 1 -> 50, 
     DataReversed -> True, 
     Epilog -> Dynamic[MapIndexed[Text[Style[#, Large], Reverse@#2 - .5] &, mat, {2}]]], 
  {{"MouseClicked", 1} :> With[{p = Reverse @ Ceiling @ MousePosition["Graphics"]}, 
       m[[## & @@ p]] += 1],
   {"MouseClicked", 2} :> With[{p = Reverse @ Ceiling @ MousePosition["Graphics"]}, 
       m[[## & @@ p]] -= 1]}], 
  {{n, 5}, 2, 20, 1}]]

enter image description here

enter image description here

Here is using Graphics

SeedRandom@2;
matrix = RandomInteger[10, {5, 5}];
MatrixForm@matrix

$\left(\begin{array}{ccccc} 8 & 4 & 5 & 4 & 7 \\ 4 & 0 & 1 & 0 & 4 \\ 3 & 7 & 3 & 0 & 2 \\ 7 & 8 & 7 & 9 & 3 \\ 6 & 2 & 3 & 8 & 9 \\ \end{array}\right)$

data = Join @@ Reverse@Table[{i, j}, {j, 5}, {i, 1, 5}];
values = Flatten@matrix;
minMax = MinMax@values;
data2 = Flatten /@ Partition[Riffle[values, data], 2];

Legended[Graphics[{EdgeForm[{Black}], 
     ColorData["DarkRainbow"][Rescale[First[#], minMax]], 
     Rectangle[Rest[#]], Black, 
     Text[First[#], Rest[#] + {0.5, 0.5}]} & /@ data2], 
 BarLegend[{"DarkRainbow", minMax}]]

enter image description here

If you want to use MatrixPlot

Overlay[{MatrixPlot[matrix, PlotRangePadding -> None, 
   ImagePadding -> None], 
  Graphics[{Opacity@0, Rectangle[Rest[#]], Opacity@1, Black, 
      Text[First[#], Rest[#] + {0.5, 0.5}]} & /@ data2, 
   PlotRangePadding -> None]}]

enter image description here

  • Please don't use JPG for non-photographic images! :) – Andreas Rejbrand Nov 10 at 11:10

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