How do I find the submatrix of a matrix?
9 ビュー (過去 30 日間)
古いコメントを表示
I'm new to Matlab so bear with me.
If I have a 2D matrix A and a submatrix B of A. How can I check if B is a submatrix of A?
I basically want to search for matrix B in A.
An example with code would be appreciated :)
0 件のコメント
採用された回答
Jos (10584)
2016 年 6 月 2 日
Here is a simple for-loop that would work for 2D cases
A = magic(6)
B = A(2:3,4:5)
% engine
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)
1 件のコメント
参考
カテゴリ
Help Center および File Exchange で Continuous Waveforms についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!