Trouble with surf
6 次查看(过去 30 天)
显示 更早的评论
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)
0 个评论
采纳的回答
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.
更多回答(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!