Where does matrix B fits best in Matrix A

조회 수: 1 (최근 30일)
Lucas Kellermann
Lucas Kellermann 2022년 1월 19일
댓글: Lucas Kellermann 2022년 1월 19일
I have a matrix A (200x200) and a matrix B (200x50).
I want to know now where B fits best in A. Maybe the nearest neighbour method can help?
Here an example what I mean:
  댓글 수: 4
Stephen23
Stephen23 2022년 1월 19일
편집: Stephen23 2022년 1월 19일
@Lucas Kellermann: does the "best fit" require 100% overlap, or can the "best fit" occur over the matrix edges?
For example, where is the "best fit" for these matrices?:
A = [999,999,999,999;999,999,999,999;999,999,1,1;999,999,1,1]
A = 4×4
999 999 999 999 999 999 999 999 999 999 1 1 999 999 1 1
B = [1,1,1;1,1,1;1,1,1]
B = 3×3
1 1 1 1 1 1 1 1 1
Lucas Kellermann
Lucas Kellermann 2022년 1월 19일
I have to do both but first step is an 100% overlap.

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

답변 (1개)

KSSV
KSSV 2022년 1월 19일
A = 5*ones(8) ;
A(4:6,4:6) = [3 4 2; 1 1 1; 2 3 3] ;
B = ones(3) ;
[m,n] = size(A) ;
count = 0 ;
v = zeros(3,3,[]) ;
R = zeros([],1) ;
for i = 1:3:(m-3)
for j = 1:3:(n-4)
count = count+1 ;
M = A(i:(i+3-1),j:(j+3-1)) ;
v(:,:,count) = M ;
R(count) = sqrt(mean((M(:) - B(:)).^2)) ;
end
end
[val,idx] = min(R) ;
iwant = v(:,:,idx)
iwant = 3×3
3 4 2 1 1 1 2 3 3

카테고리

Help CenterFile Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by