when i plot a function, others disappear

1 visualizzazione (ultimi 30 giorni)
Omer Seker
Omer Seker il 10 Apr 2022
Modificato: Torsten il 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

Risposte (1)

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

Accedi per commentare.

Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by