0
$\begingroup$

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?

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

1 Answer 1

2
$\begingroup$

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}} *)
$\endgroup$
2
  • $\begingroup$ 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??? $\endgroup$ May 28, 2018 at 10:18
  • $\begingroup$ sirr any short program that will be helpfull for such coding $\endgroup$ May 28, 2018 at 10:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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