1
我试图通过将它从极坐标转换为直角坐标并使用surf()
来绘制它来绘制3D极坐标图的图形。Matlab中的3D绘图
问题:我得到错误??? CData must be an M-by-N matrix or M-by-N-by-3 array
。我哪里做错了?我对MATLAB很陌生,不明白发生了什么。
MATLAB代码
清除所有; 关闭所有;
N=50;
%define matrices for ploting
x=zeros(N,N,N);
y=zeros(N,N,N);
z=zeros(N,N,N);
f=zeros(N,N,N);
%define basic input variables
r=linspace(0,2,N);
theta=linspace(0,pi,N);
phi=linspace(0,2.*pi,N);
for ii=(1:N) %use ii, jj to avoid confusion with the imaginary units
for jj=(1:N)
for kk=(1:N)
x(ii,jj,kk)=r(ii).*sin(theta(jj)).*cos(phi(kk)); %%not using
%%for loop probably can work too, test later
y(ii,jj,kk)=r(ii).*sin(theta(jj)).*sin(phi(kk));
z(ii,jj,kk)=r(ii).*cos(theta(jj));
f(ii,jj,kk)=r(ii).*exp(-r(ii)).*cos(theta(jj));
end
end
end
figure;
surf(x,y,z,f);
colormap([1,1,1]);