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

33 vues (au cours des 30 derniers jours)
Rebeka le 12 Avr 2023
Modifié(e) : Cris LaPierre le 13 Avr 2023
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")
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

Cris LaPierre le 12 Avr 2023
Modifié(e) : Cris LaPierre le 13 Avr 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
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Rebeka le 13 Avr 2023
Thanks a lot for pointing out the mistake and also for answering my question.

Connectez-vous pour commenter.

### Plus de réponses (1)

Antoni Garcia-Herreros le 12 Avr 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
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Rebeka le 13 Avr 2023
Thank you.

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Surface and Mesh Plots dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by