How to extract all larger sub-matrices

I have a matrix:

Q = [05 11 12 16 25;
     17 18 02 07 10;
     04 23 20 03 01;
     24 21 19 14 09;
     06 22 08 13 15]

I would like to list all the possible 3x3 matrices. Here are some examples:

11 12 16;
18  2  7;
23 20  3

and

 5 11 12;
17 18  2;
 4 23 20;

etc. In principle, all possible matrices are 3 by 3. How can I do this? Should I use a loop for?

+3
source share
2 answers

If you have an Image Processing Toolbox , you can use the IM2COL function :

subMats = im2col(Q,[3 3]);

Each column of subMatscontains elements of a 3 by 3 matrix extracted from Q. Each of these columns can be converted to a 3 by 3 matrix as follows:

Q1 = reshape(subMats(:,1),[3 3]);  %# Reshape column 1 into a 3-by-3 matrix
+5
source

, ( , , ), .

  • 5x5.
  • 3x3 5x5. , ?
  • . ?
  • . ?

, ?

0

Source: https://habr.com/ru/post/1765658/


All Articles