when i plot a function, others disappear
8 次查看(过去 30 天)
显示 更早的评论
When i write the code below, matlab does not plot all the functions but one. you can see what i mean. Where did i make a mistake? Thank you for upcoming helps.
t = [-5:0.1:10];
x = t.^3 - 2*t + 9;
y = 6*t.^5 - t;
z = t.^2 + 7;
plot(t,x,'r:')
hold on
plot(t,y,'g--')
hold on
plot(t,z,'b-.')
hold off
0 个评论
回答(1 个)
the cyclist
2022-4-10
编辑:the cyclist
2022-4-10
All three lines are being plotted. The issue is that the green line goes to huge values, so you don't see the separation between the other two. Here, I've plotted over a much smaller range, so you see that:
t = [-1.5:0.01:1.5];
x = t.^3 - 2*t + 9;
y = 6*t.^5 - t;
z = t.^2 + 7;
plot(t,x,'r:')
hold on
plot(t,y,'g--')
hold on
plot(t,z,'b-.')
hold off
FYI, you don't need to repeatedly use hold on ...
t = -1.5:0.01:1.5
x = t.^3 - 2*t + 9;
y = 6*t.^5 - t;
z = t.^2 + 7;
figure
hold on
plot(t,x,'r:')
plot(t,y,'g--')
plot(t,z,'b-.')
hold off
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
