How do I cut a surface in Matlab plot?

7 ビュー (過去 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 Center および File ExchangeSurface and Mesh Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by