MATLAB: I want to draw sphere

sphere

I have this code
r = 1;
xo = 0;
yo = 0;
zo = 0;
m =20;
n = 10;
for theta=0:2*pi/m:2*pi, phi=-pi/2:pi/10:pi/2
x = xo + r *cos(phi)* cos(theta)
y = yo + r *cos(phi)* sin(theta)
z = zo + r *sin(phi)
end
i want get coordinates of x, y, z at each point on the sphere.
here i am changing the values of thera and phi in same for loop.
IS ir right? please help me.

Best Answer

r = 1;
xo = 0;
yo = 0;
zo = 0;
m =20;
n = 10;
theta=0:2*pi/m:2*pi ;
phi=-pi/2:pi/10:pi/2 ;
[T,P] = meshgrid(theta,phi) ;
X = xo + r *cos(P).* cos(T);
Y = yo + r *cos(P).* sin(T);
Z = zo + r *sin(P) ;