% find the maximum possible size of a square in (x,y) function res = randSqr(x,y,A,mSize) sizeA = length(A); %size=0; res=mSize; for size=[2:1:mSize] if max(max(A(x:x+size-1,y:y+size-1))) > 0 res=size-1 ; break; end end end