Basically, i want to scan a small matrix over bigger matrix and then compare it's elements one by one for greater or less than bigger matrix.The comparison can be done in either way through column or through row.
Not by looping, however try
%% a=[1,2;3,4]; b=[1,5,6;4,0,8;11,12,0]; %% sza = size( a ); is_greater_equal = ( a >= b(1:sza(1),1:sza(2)) )
is_greater_equal = 1 0 0 1
and to find the indicies
>> [ixr,ixc]=find(is_greater_equal) ixr = 1 2 ixc = 1 2
Please explain what you're trying to do, rather than how you want to solve it. Because I'm thinking that normalized cross correlation (with function normxcorr2) will help you but I'm not really sure what you want to do. And don't just say you want to scan a large matrix with a small one, say WHY you want to do that so we know whether to recommend normxcorr2() or blockproc(), or if you really need nested looping.
B=randi(100,9) % the big matrix [n,m]=size(B); S=randi(100,3) % the small matrix out=; for id1=1:3:n-3 for id2=1:3:m-3 a=B(id1:id1+2,id2:id2+2); out=[out;a(a>=S)]; end end
B=randi(100,512,512) ; % the big matrix [n,m]=size(B); S=randi(100,256,20) % the small matrix [n1,m1]=size(S); q1=fix(n/n1); q2=fix(m/m1); idxr= [ n1*ones(1,q1) n-n1*q1]; idxc=[m1*ones(1,q2) m-m1*q2]; idxc(~idxc)=; idxr(~idxr)=; out=; ii0=1; for id1=1:numel(idxr) ii1=ii0+idxr(id1)-1; jj0=1; for id2=1:numel(idxc) jj1=jj0+idxc(id2)-1; a=B(ii0:ii1,jj0:jj1); [nn,mm]=size(a); b=S(1:nn,1:mm); out=[out;a(a>=b)]; jj0=jj1+1; end ii0=ii1+1; end