Adding z-values for surf/contour plots

조회 수: 1 (최근 30일)
Hannes Furuholm
Hannes Furuholm 2011년 2월 21일
Hi! I have a cone which I can plot two times with a minor displacement like this:
p=0:1:40; [X,Y,Z] = cylinder([10 0]); Z=Z*length(p);
axis equal; surf(X,Y,Z) hold on surf(X+3,Y+4,Z)
However, what I would like to do is to add the z-values for the cones wherever they might intersect. Thus creating more of a mountain-like shape. My code is probably completely wrong for what I want to do, but hopefully it at least might show what I´m after.
Is this possible?
// Hannes

채택된 답변

Matt Tearle
Matt Tearle 2011년 2월 21일
Is this what you're after? I'm not sure if you mean "add" the z-values literally (z1 + z2) or "add" in the sense of append to the plot. For the former interpretation:
[x,y] = meshgrid(-10:0.2:15);
z1 = 42 - 4.2*sqrt(x.^2+y.^2);
z2 = 42 - 4.2*sqrt((x-3).^2+(y-4).^2);
z1(z1<0) = 0;
z2(z2<0) = 0;
figure
surf(x,y,z1,'linestyle','none')
hold on
surf(x,y,z2,'linestyle','none')
figure
z3 = z1+z2;
surf(x,y,z3,'linestyle','none')
To get rid of the "land" at z = 0, you can also do:
z3(z3==0)=NaN;
figure
surf(x,y,z3,'linestyle','none')
  댓글 수: 2
Hannes Furuholm
Hannes Furuholm 2011년 2월 21일
That was exactly what I wanted to do, I honestly can't thank you enough! I tried with meshgrid and cone-equations myself, but it's hard when you don't have any skills =)
Matt Tearle
Matt Tearle 2011년 2월 22일
Once again Logical Indexing Man triumphs over the forces of darkness and confusion!

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

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