Hi Raymond,
your inequality conditions must be done each by itself: replace
if d(1,1)&&d(1,2)<.5
by
if d(1,1)<0.5 && d(1,2)<0.5
and likewise for the others. What you wrote is essentially
if d(1,1)~=0 && d(1,2)<.5
which is more or less the same as d(1,2)<0.5 since rand very seldom hits exactly zero.
Titus
