Trouble with surf

6 次查看(过去 30 天)
Adam Anderson
Adam Anderson 2012-2-7
I am trying to plot the surface of a sphere but keep running into trouble in the z variable of my code. I have tried to resize the ra variable to the same size as y and x by multiplying it by a ones vector before sending it into z. I have tried carrying out the operations in z with element wise power . and without. I am actually pretty disappointed in myself that I can not seem to figure out an easy problem such as this. I have it sized right now but z keeps getting imaginary numbers which the system will not plot. The length of ra and theta were predetermined to be 10 and 22. Here is what I have so far. Thanks in advance for any help provided.
theta=linspace(0,2*pi,22)
ra=linspace(0,1,10)
x=(ra'*cos(theta))
y=(ra'*sin(theta))
r1=ones(22,1)*ra
r2=r1'
z=abs(sqrt(r2.^2-x.^2-y.^2))
surf(x,y,z)

采纳的回答

Andreas Goser
Andreas Goser 2012-2-7
Your code executes fine on my machine. z is not complex in my case.
One idea I have is, that you have multiple ABS functions on you path.
which abs -all
Should just return paths to MATLAB builtin functions. Please verify.
  1 个评论
Adam Anderson
Adam Anderson 2012-2-7
Are you getting a whole sphere or just the top half?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by