x=-1:0.001:1;
y=-1:0.01:1;
[X,Y]=meshgrid(x,y);
Z=sqrt(1-(X.^2+Y.^2));
Z(find(imag(Z)~=0))=nan;
mesh(X,Y,Z)
hold on
mesh(X,Y,-Z)
但是中心数据少不好看,建议用极坐标画
t=linspace(0,pi,100);
p=linspace(0,2*pi,100);
[theta,phi]=meshgrid(t,p);
x=sin(theta).*sin(phi);
y=sin(theta).*cos(phi);
z=cos(theta);
mesh(x,y,z);
axis equal;
温馨提示:答案为网友推荐,仅供参考