How to add a line on the surface plot at a specific x value?
조회 수: 62 (최근 30일)
이전 댓글 표시
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
채택된 답변
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개)
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 Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!