surf plot using meshgrid?

조회 수: 21 (최근 30일)
alibaba alibabu
alibaba alibabu 2020년 4월 26일
편집: alibaba alibabu 2020년 4월 26일
Good day
Pleas advise for code error. First figure is OK. 2nd one is incorrect.
Whei statments z<100 and 100<=z<200 are not taken in to accounte?
x=0:300;
y=x;
[xx,yy]=meshgrid(x,y);
z=(xx+yy)/2;
figure
surf(x,y,z)
if z<100;
k=z;
elseif z>=100 & z<200;
k=100;
else
k=z-100;
end
figure
surf(x,y,k)

채택된 답변

Tommy
Tommy 2020년 4월 26일
As z is an array, the following two statements
if z<100
and
elseif z>=100 & z<200
will only be true if every element within z satisfies the conditions, so you always end up with the third result (k=z-100).
To apply the if elseif statements to every element within z, try
x=0:300;
y=x;
[xx,yy]=meshgrid(x,y);
z=(xx+yy)/2;
figure
surf(x,y,z,'EdgeColor','none')
k = z;
k(z>=100) = z(z>=100)-100;
k(z>=100&z<200) = 100;
figure
surf(x,y,k,'EdgeColor','none')
  댓글 수: 1
alibaba alibabu
alibaba alibabu 2020년 4월 26일
편집: alibaba alibabu 2020년 4월 26일
Thx for prompt help.

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

추가 답변 (1개)

David Hill
David Hill 2020년 4월 26일
y=x;
[xx,yy]=meshgrid(x,y);
z=(xx+yy)/2;
figure
s=surf(xx,yy,z);
s.EdgeColor = 'none';%turns black if too many points
if z<100
k=z;
elseif z>=100 & z<200
k=100;
else
k=z-100;
end
figure
f=surf(xx,yy,k);
f.EdgeColor = 'none';

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by