The above code is not able to generate spheres primarily because in the workflow any point that is less than r1 is given a true value by giving it 1 whereas for a sphere the points should be all equidistant from a center. To plot a sphere with center at (a,b,c) and radius r, refer to the following code:
[x,y,z] = sphere;
x = x*r;
y = y*r;
z = z*r;
figure
surf(x+a,y+b,z+c)