I have a big matrix, you can say 1000*1000 whose elements are functions of several parameters such as a, b. I wish to see just a few (not all) rows and columns of the matrix in the MatrixForm which is a builtin function of Mathematica. For instance, row from 92 to 101 and column corresponded with 50 to 65. How can I reach this goal? In addition, if I want to simplify the elements, should I simply firstly and after that make use of MatrixForm or should I do vise versa? Which one is faster to run?


2 Answers 2


Here is a function that shows a portion of a matrix in MatrixForm, with associated row and column indices:

iMatrixView[m_, r_List, c_List] := Module[{sub = m[[r, c]]},
    augmented = ArrayFlatten[{
        {Map[Invisible, sub, {2}], List /@ istyle /@ r},
        {{istyle /@ c}, ""}
        Row[{RawBoxes@"(", Grid[sub, Spacings->1],RawBoxes@")"}],
        Row[{Invisible[RawBoxes@"("],Grid[augmented, Spacings->1]}]

istyle[x_] := Style[x, Gray, FontSize->Inherited-3]

For example:

mat = RandomInteger[150, {10, 15}];
iMatrixView[mat, {2,4,5}, {1, 6, 12}]

enter image description here

It is possible to use this function in a Manipulate to interactively explore the matrix:

MatrixView[mat_?MatrixQ, rows_Integer?Positive, cols_Integer?Positive] := With[

        {{u, {0,dim[[1]]-rows}}, {0,0}, Reverse@dim-{cols,rows}, 1}
    ] /; rows<dim[[1]]&&cols<dim[[2]]

For example:

MatrixView[mat, 6, 5]

enter image description here

  • $\begingroup$ Wonderful and Professional. Thanks so much $\endgroup$ Apr 21, 2019 at 1:32
M = RandomInteger[10, {1000, 1000}]; 
M // MatrixForm;

SubM = M[[92 ;; 101 , 50 ;; 65]];
SubM // MatrixForm

In terms of simplifying, it depends on a few things. Assuming that you only want to simplify the entries that you're extracting I think it'd be quicker to extract first, then simplify. If you simplify first then extract I'd think its almost equivalent to extracting twice since you first need to tell the computer which cells you want to simplify, which takes some time, then simplify them, then extract them, when if you extract them first and then simplify the whole thing, there are only two operations required, which logically should be quicker. Hope that helps.

  • $\begingroup$ your answer helped me fundamentally. Thank you so much $\endgroup$ Apr 21, 2019 at 1:31

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.