Trouble with surf

8 vues (au cours des 30 derniers jours)
Adam Anderson
Adam Anderson le 7 Fév 2012
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)

Réponse acceptée

Andreas Goser
Andreas Goser le 7 Fév 2012
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 commentaire
Adam Anderson
Adam Anderson le 7 Fév 2012
Are you getting a whole sphere or just the top half?

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by