Remove a "plane" from my 3d plot

조회 수: 9 (최근 30일)
davidcu
davidcu 2021년 10월 14일
편집: Ravi Narasimhan 2021년 10월 14일
When I plot the surface it results into the surface itself but there is something weird in the middle of the surface, I mean it's kind like it is in the xy plane, I do not know how to remove it, here is my code:
clear
figure, hold on
[x,y]=meshgrid(-50:50)
xlabel ("x");
ylabel ("y");
zlabel ("z")
z=sqrt(9*(y.^2)-9*(x.^2))
w=-sqrt(9*(y.^2)-9*(x.^2))
surf(x,y,real(z))
surf(x,y,real(w))
zlim([-150,150])
  댓글 수: 3
davidcu
davidcu 2021년 10월 14일
I have tried with that restriction, but I got this error "mesh: X, Y, Z arguments must be real". Or in what way do I have to write the restriction?
Ravi Narasimhan
Ravi Narasimhan 2021년 10월 14일
편집: Ravi Narasimhan 2021년 10월 14일
You could perhaps set any value of real(z) or real(w) = 0 to NaN (Not a Number) using the find function. Those items wouldn't display on the surface plot, leaving a space between the top and bottom halves. It would look like
z(find(real(z) == 0)) = NaN;
The find function returns the indices where real(z) == 0 and the z(find(...)) = NaN sets those positions in the z array to NaN
You'd tweak it accordingly for w.
Addendum: Posted while @DGM's answer came in.

댓글을 달려면 로그인하십시오.

채택된 답변

DGM
DGM 2021년 10월 14일
You could try to clip off the excess points with NaN and be left with a gap in the surface at the joint, or you could just avoid the problem entirely.
Consider this:
N = 50;
th = linspace(0,2*pi,N);
r = linspace(-50,50,N).';
[x z y] = pol2cart(th,r,r);
z = z*3; % your example stretches on z
h = surf(x,y,z);
set(h,'facealpha',0.8,'edgealpha',0.5)
axis equal
xlabel ("x");
ylabel ("y");
zlabel ("z")

추가 답변 (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