What am I doing wrong here I keep getting a plot with either to many things on it or not enough all I want is a plot with two y axis and an x axis

1 次查看(过去 30 天)
theta = 46.97;
theta2= 55;
v1= 13.5;
v2= 16.05;
x= (0:0.1:2.3);
x2= (0:0.1:5.14);
y= x*tan(theta)-(g/(2*v1.^2*cos(theta).^2))*x.^2;
y1= x2*tan(theta2)-(g/(2*v2.^2*cos(theta2).^2))*x2.^2;
yyaxis right
plot(x,y)
plot(x2,y1)
hold on

采纳的回答

Alan Stevens
Alan Stevens 2021-1-13
Like this
g = 9.81;
theta = 46.97;
theta2= 55;
v1= 13.5;
v2= 16.05;
x= (0:0.1:2.3);
x2= (0:0.1:5.14);
y= x*tan(theta)-(g/(2*v1.^2*cos(theta).^2))*x.^2;
y1= x2*tan(theta2)-(g/(2*v2.^2*cos(theta2).^2))*x2.^2;
plotyy(x,y,x2,y1),grid
  2 个评论
Alan Stevens
Alan Stevens 2021-1-13
It worked for me! However, an alternative is
g = 32.2;
theta = 46.97;
theta2= 55;
v1= 13.5;
v2= 16.05;
x= (0:0.1:2.3);
x2= (0:0.1:5.14);
y= x*tan(theta)-(g/(2*v1.^2*cos(theta).^2))*x.^2;
y1= x2*tan(theta2)-(g/(2*v2.^2*cos(theta2).^2))*x2.^2;
plot(x,y),grid
ylabel('y')
yyaxis right
plot(x2,y1)
ylabel('y1')
xlabel('x')
This results in

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by