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

 채택된 답변

KSSV
KSSV 2020년 4월 10일

0 개 추천

댓글 수: 3

han
han 2020년 4월 10일
편집: darova 2020년 4월 10일
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
darova
darova 2020년 4월 10일
rout and cout are indices of A matrix, where A=B
han
han 2020년 4월 10일
ahh i see, thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

질문:

han
2020년 4월 10일

댓글:

han
2020년 4월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by