when i plot a function, others disappear
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
the cyclist
on 10 Apr 2022
Edited: the cyclist
on 10 Apr 2022
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
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!