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!