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

22 views (last 30 days)
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")

Accepted Answer

Cris LaPierre
Cris LaPierre on 12 Apr 2023
Edited: Cris LaPierre on 13 Apr 2023
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

More Answers (1)

Antoni Garcia-Herreros
Antoni Garcia-Herreros on 12 Apr 2023
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

Community Treasure Hunt

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

Start Hunting!