How to plot a line of zero value on a surface?

19 次查看(过去 30 天)
I used surf to generate a 3D surface and see it in 2D view (see below)
The dataset and code are also attached.
X=[0 0.25 0.5 0.75]'; % 4*1 vector
load Y.mat % 36*4 matrix
load Z.mat % 36*4 matrix
figure
set(gcf,'position',[100,100,1000,750]);
surf(X, Y, Z, 'EdgeColor', 'none', 'FaceColor', 'interp');
hold on;
colormap(coolwarm(256)); caxis([-0.35 0.35]); colorbar;
patch([0,0.8,0.8,0],[0.8,0.8,0,0],[0,0,0,0],[1,1,1,1],'FaceAlpha',0.5,'EdgeColor',[0,0,0]);
grid off; view(2);
Now I want to plot the intersection of surface and zero-plane, can anyone help to with that? Thanks!

采纳的回答

Star Strider
Star Strider 2022-12-13
Use contour3 to draw the boundary (here a red line with 'LineWidth',5) —
LD1 = load(websave('Y','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1230092/Y.mat'));
Y = LD1.Amp;
LD2 = load(websave('Z','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1230097/Z.mat'));
Z = LD2.Pnet;
X=(ones(size(Z,1),1)*[0 0.25 0.5 0.75]);
% 4*1 vector
% load Y.mat % 36*4 matrix
% load Z.mat % 36*4 matrix
figure
set(gcf,'position',[100,100,1000,750]);
surf(X, Y, Z, 'EdgeColor', 'none', 'FaceColor', 'interp');
hold on;
colormap(turbo(256)); caxis([-0.35 0.35]); colorbar;
patch([0,0.8,0.8,0],[0.8,0.8,0,0],[0,0,0,0],[1,1,1,1],'FaceAlpha',0.5,'EdgeColor',[0,0,0]);
contour3(X, Y, Z, [0 0], '-r', 'LineWidth',5)
grid off
view(-160,30)
% view(2);
The plane at ‘Z=0’ partially obscures the line.
.
  4 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by