How do I cut a surface in Matlab plot?

조회 수: 41 (최근 30일)
Hamid Attar
Hamid Attar 2020년 5월 19일
답변: darova 2020년 5월 19일
Hello,
I have a function f(x) which is in 2D, allowing me to make surf plot. To make the surf plot, I discretise the space and do 2 for loops over the x and y indecies to get a matrix of Z values. I then use the surf command to plot this surface.
However, I would like to cut the surface at all Z values above a critical value to produce a smooth boundary. I do this by simply removing the values of the Z matrix which are above a critical value by setting those to "nan".
When I plot this new Z matrix (with some enteries as "nan") , I get a choppy border, see the figures below. I know this is because my space is discretised into a finite grid of points, and I could just increase the number of points, however since the function is expensive to evaluate, I don't want to do this methid.
Is there another way to plot the surface with a smooth boundary?
Many thanks.

답변 (1개)

darova
darova 2020년 5월 19일
Do you have a contour? Green line?
[x,y,z] = peaks(20);
% some contour data
data = [-0.3907 1.5591
-1.8039 0.6908
-0.8456 -0.8716
1.7243 -0.8535
1.3515 0.7998];
x1 = data(:,1);
y1 = data(:,2);
gd = [2; length(x1); x1(:); y1(:)]; % geometry
dl = decsg(gd); % decomposition of geomtry
[p,e,t] = initmesh(dl); % mesh
z1 = interp2(x,y,z,p(1,:),p(2,:)); % get 'z' coordinate
ff.vertices = [p' z1(:)];
ff.faces = t(1:3,:)';
ff.facecolor= 'y';
surf(x,y,z,'facecolor','none')
line(x1,y1,y1*0+5,'linew',3)
patch(ff)
axis vis3d

카테고리

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