Find a submatrix in a matrix

Hi,
I am trying to find the colums and rows in a large matrix that contain the submatrix.
Say we have
T = [0,3,0,0,0,0;3,0,4,0,8,0;0,4,0,1,0,0;0,0,1,0,0,0;0,8,0,0,0,6;0,0,0,0,6,0]
0 3 0 0 0 0
3 0 4 0 8 0
0 4 0 1 0 0
0 0 1 0 0 0
0 8 0 0 0 6
0 0 0 0 6 0
and we have a submatrix of
S = [0,3,0,0;3,0,4,0;0,4,0,1;0,0,1,0]
0 3 0 0
3 0 4 0
0 4 0 1
0 0 1 0
how can we find the rows and columns in T that contain submatrix S please?
TIA

 Accepted Answer

KSSV
KSSV on 10 Apr 2020

3 Comments

han
han on 10 Apr 2020
Edited: darova on 10 Apr 2020
Hi,
I changed S and T to be A and B
I am new to MATLAB so sorry if I am missing something here
In the second link i used the below:
szA = size(A) ;
szB = size(B) ;
szS = szA - szB + 1
tf = false(szA) ;
for r = 1:szS(1)
for c = 1:szS(2)
tf(r,c) = isequal(A(r:r+szB(1)-1,c:c+szB(2)-1),B)
end
end
[rout,cout] = find(tf)
Rout was equal to 1 and cout was equal to 1,
I need to find the columns in the large matrix that contain the sub matrix
Thank you
rout and cout are indices of A matrix, where A=B
ahh i see, thank you!

Sign in to comment.

More Answers (0)

Categories

Asked:

han
on 10 Apr 2020

Commented:

han
on 10 Apr 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!