I have a large matrix and I want to extract different sub-matrices that actually have elements on different positions. Using Extract and mention the position of every element is quiet tedious and will take too much time to type.

What command can I use to extract the required elements? For example I want to extract 2*2 matrix with these elements

{{[[1, 1]], [[1, 9]]}, {[[9, 1]], [[9, 9]}}

Is there another way where I don't have to specify the position of the elements repeatedly?

• Please provide a MWE. May 27, 2018 at 12:35
• What do you mean by nested [...]s in nested {...}s? As far as I know, it does not make sense in Mathematica. May 27, 2018 at 12:39
• Do you just want to identify where non zero elements are? May 29, 2018 at 16:18
• not actually, but my purpose is to just extract different submatrix repeatdly from a matrix May 30, 2018 at 9:26

If I understand you correctly, then for this type of problem, you can use the following shorter notation. I use a random matrix m as a test:

m = RandomInteger[9, {10, 10}];
m[[{1, 9}, {1, 9}]]

(* {{8, 6}, {3, 9}} *)

This should be the same as specifying it manually

{{m[[1, 1]], m[[1, 9]]}, {m[[9, 1]], m[[9, 9]]}}
(* {{8, 6}, {3, 9}} *)
• sirr it is goood but what i doo if i have such type of code[{{Q[[1, 1]], Q[[1, 7]], Q[[1, 6]], Q[[1, 9]], Q[[1, 15]], Q[[1, 14]]}, {Q[[7, 1]], Q[[7, 7]], Q[[7, 6]], Q[[7, 9]], Q[[7, 15]], Q[[7, 14]]}, {Q[[6, 1]], Q[[6, 7]], Q[[6, 6]], Q[[6, 9]], Q[[6, 15]], Q[[6, 14]]}, {Q[[9, 1]], Q[[9, 7]], Q[[9, 6]], Q[[9, 9]], Q[[9, 15]], Q[[9, 14]]}, {Q[[15, 1]], Q[[15, 7]], Q[[15, 6]], Q[[15, 9]], Q[[15, 15]], Q[[15, 14]]}, {Q[[14, 1]], Q[[14, 7]], Q[[14, 6]], Q[[14, 9]], Q[[14, 15]], Q[[14, 14]]}}] how it can be simplify??? May 28, 2018 at 10:18
• sirr any short program that will be helpfull for such coding May 28, 2018 at 10:52