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

49 ビュー (過去 30 日間)
Rebeka
Rebeka 2023 年 4 月 12 日
編集済み: Cris LaPierre 2023 年 4 月 13 日
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
Cris LaPierre 2023 年 4 月 12 日
編集済み: Cris LaPierre 2023 年 4 月 13 日
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 件のコメント
Rebeka
Rebeka 2023 年 4 月 13 日
Thanks a lot for pointing out the mistake and also for answering my question.

サインインしてコメントする。

その他の回答 (1 件)

Antoni Garcia-Herreros
Antoni Garcia-Herreros 2023 年 4 月 12 日
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

カテゴリ

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