how do i compare two matrices with different sizes.so that i get to know when elements of smaller matrix are exactly matched to elements in larger matrix?

2 次查看(过去 30 天)
i need assistance in my object detection project.

采纳的回答

dpb
dpb 2015-5-13
编辑:dpb 2015-5-14
"Dead ahead" solution -- it's undoubtedly doable via conv2 or the like and there may be something in the Image Processing Toolbox (I don't have) that is even better but the brute force route would be something like--
[M,N]=size(R); % the larger array
[m,n]=size(r); % and the smaller...
for i=1:M/m-(m-1)
for j=1:N/n-(n-1)
if all(r==R(i:i+m-1,j:j+n-1))
disp('found')
end
end
end
Above presumes M/m == fix(M/m) and ditto for N/n...
ERRATUM Correct limits on subset indices; had done a local sanity check test using a 2x2 and had hardcoded 'i+1' that missed in the generalization to arbitrary size.

更多回答(1 个)

dpb
dpb 2015-5-12
doc ismember % maybe?
NB: if are floating point values you'll probably need to use an inexact comparison to ensure "close enough" is still seen as "equal".
  1 个评论
Shoaib Ejaz
Shoaib Ejaz 2015-5-12
There are only binary values in both matrices, what I want is that using for loop matlab will tell how many times both matrices are matched, if you got my point.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by