Drawing upside down cone using spherical coordinates.
5 次查看(过去 30 天)
显示 更早的评论
I wrote the following code:
phi=pi/6;
theta=linspace(0,2*pi,63); %Theta goes from 0 to 2*pi.
a=linspace(0,1,21);
[PHI,THETA,A]=meshgrid(phi,theta,a);
X=A.*sin(PHI).*cos(THETA); % Spherical coordinates
Y=A.*sin(PHI).*sin(THETA);
Z=A.*cos(PHI);
surf(X,Y,Z)
axis equal
It won't draw, but instead gives me an empty 2D graph.
The error message is:
Error using matlab.graphics.chart.primitive.Surface
Value must be a vector or 2D array of numeric type.
hh = matlab.graphics.chart.primitive.Surface(allargs{:});
0 个评论
采纳的回答
Benjamin Kraus
2021-4-30
The issue you are facing is that when you call meshgrid you are specifying three input vectors, so the output matrices are going to be 3D matrices, but surf only accepts 2D matrices.
My recommendation is to remove phi from the call to meshgrid:
phi=pi/6;
theta=linspace(0,2*pi,63);
a=linspace(0,1,21);
[THETA,A]=meshgrid(theta,a);
X=A.*sin(phi).*cos(THETA);
Y=A.*sin(phi).*sin(THETA);
Z=A.*cos(phi);
surf(X,Y,Z)
axis equal
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!