when i plot a function, others disappear

1 view (last 30 days)
Omer Seker
Omer Seker on 10 Apr 2022
Edited: Torsten on 10 Apr 2022
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

Answers (1)

the cyclist
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
  1 Comment
Omer Seker
Omer Seker on 10 Apr 2022
thank you so much for the reply and also thanks for the hold on shortcut

Sign in to comment.

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!