# How to add a line on the surface plot at a specific x value?

13 次查看（过去 30 天）
Rebeka 2023-4-12

I have a surface plot and I want to highlight some values on the surface, say at few specific x values. How do I do that? Below is the example of a graph where two surfaces are being plot. I want to show the lines on surface say at x=1,5, 10.
clc;
clear all;
g=1;
l1=1;
w0= sqrt(g/l1);
[mu,a]=meshgrid(0.01:0.2:20,0.01:0.2:20);
w1=w0*sqrt(((1+mu)/2).*(1+a))*sqrt(1+sqrt(1-(4./((1+mu).*(2+a+(1./a))))));
w2=w0*sqrt(((1+mu)/2).*(1+a))*sqrt(1-sqrt(1-(4./((1+mu).*(2+a+(1./a))))));
omega1=w1;
omega2=w2;
surf(mu,a,omega1,'FaceAlpha',0.4,'EdgeColor',"none",'FaceColor',"flat")
hold on
surf(mu,a,omega2,'FaceAlpha',0.4,'EdgeColor',"none",'FaceColor',"flat") ### 采纳的回答

Cris LaPierre 2023-4-12

Repeat the same process you did for making your surface, just adjust the x values to be your desired values.
Note, I think you meant to use an elementwise operator between your two terms. I've commented below.
g=1;
l1=1;
w0= sqrt(g/l1);
[mu,a]=meshgrid(0.01:0.2:20,0.01:0.2:20);
% vv <------changed to elementwise operator
omega1=w0*sqrt(((1+mu)/2).*(1+a)).*sqrt(1+sqrt(1-(4./((1+mu).*(2+a+(1./a))))));
omega2=w0*sqrt(((1+mu)/2).*(1+a)).*sqrt(1-sqrt(1-(4./((1+mu).*(2+a+(1./a))))));
x = [1,5, 10];
[mux,ax]=meshgrid(x,0.01:0.2:20);
x1 = w0*sqrt(((1+mux)/2).*(1+ax)).*sqrt(1+sqrt(1-(4./((1+mux).*(2+ax+(1./ax))))));
x2 = w0*sqrt(((1+mux)/2).*(1+ax)).*sqrt(1-sqrt(1-(4./((1+mux).*(2+ax+(1./ax))))));
surf(mu,a,omega1,'FaceAlpha',0.4,'EdgeColor',"none",'FaceColor',"flat")
hold on
surf(mu,a,omega2,'FaceAlpha',0.4,'EdgeColor',"none",'FaceColor',"flat")
plot3(mux,ax,x1)
plot3(mux,ax,x2)
hold off ##### 1 个评论显示 -1更早的评论隐藏 -1更早的评论
Rebeka 2023-4-13
Thanks a lot for pointing out the mistake and also for answering my question.

### 更多回答（1 个）

Hello Rebeka,
You can try something like:
clc;
clear all;
g=1;
l1=1;
w0= sqrt(g/l1);
[mu,a]=meshgrid(0.01:0.2:20,0.01:0.2:20);
w1=w0*sqrt(((1+mu)/2).*(1+a))*sqrt(1+sqrt(1-(4./((1+mu).*(2+a+(1./a))))));
w2=w0*sqrt(((1+mu)/2).*(1+a))*sqrt(1-sqrt(1-(4./((1+mu).*(2+a+(1./a))))));
omega1=w1;
omega2=w2;
surf(mu,a,omega1,'FaceAlpha',0.4,'EdgeColor',"none",'FaceColor',"flat")
hold on
surf(mu,a,omega2,'FaceAlpha',0.4,'EdgeColor',"none",'FaceColor',"flat")
plot3(ones(100,1),linspace(0,20,100),omega1(:,5),'LineWidth',2); % Plot line on omega 1 X=1
plot3(10*ones(100,1),linspace(0,20,100),omega1(:,50),'LineWidth',2); % Plot line on X=10
plot3(15*ones(100,1),linspace(0,20,100),omega1(:,75),'LineWidth',2); % Plot line on X=15 Rebeka 2023-4-13
Thank you.

### 类别

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!