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.
0 个评论
采纳的回答
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.
0 个评论
更多回答(1 个)
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".
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multidimensional Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!