Drawing upside down cone using spherical coordinates.
10 ビュー (過去 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!