0

I am working on a matrix problem where I have an m*n matrix and I want to extract all 5*5 matrices from it by shifting one row and column but I am not able to extract all the 5*5 matrices but only once. Can you help me extract all the matrices?

I am able to extract the using Basic operations but how to extract all the submatrices using a loop

A=[(40 45 50 60 70 80), (10 12 15 17 18 20), (35 41 57 44 98 78), (45 74 11 2 36 78), (12 45 79 85 36 45), (1 5 8 78 47 3)]

A(1:5,1:5)

example input: [(40 45 50 60 70 80), (10 12 15 17 18 20), (35 41 57 44 98 78), (45 74 11 2 36 78), (12 45 79 85 36 45), (1 5 8 78 47 3)]

output: [(40 45 50 60 70), [(45 50 60 70 80), (10 12 15 17 18 ), (12 15 17 18 20), (35 41 57 44 98), (41 57 44 98 78), (45 74 11 2 36 ), (74 11 2 36 78), (12 45 79 85 36) ] (45 78 85 36 45)]

Something like this, I am able to extract the first output but not all the output enter image description here

Amr Eladawy
  • 4,193
  • 7
  • 34
  • 52

1 Answers1

0

This should let you have all the sub matrices in cell array B

clear all;
A=[40 45 50 60 70 80; 10 12 15 17 18 20; 35 41 57 44 98 78; 45 74 11 2 36 78; 12 45 79 85 36 45; 1 5 8 78 47 3]
for i=1:size(A,1)-4
    for j=1:size(A,2)-4
        B{i,j}=A(i:i+4,j:j+4)
    end
end
Nirvedh Meshram
  • 439
  • 6
  • 13