【发布时间】:2011-11-12 23:31:17
【问题描述】:
我正在尝试通过将极坐标转换为笛卡尔坐标并使用surf() 来绘制 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]);
【问题讨论】:
标签: matlab