Plotting multiple lines on same graph

33 Ansichten (letzte 30 Tage)
Dominique Davis
Dominique Davis am 26 Nov. 2019
Kommentiert: Star Strider am 27 Nov. 2019
Hello! I am trying to plot multiple lines on the same graph but "hold on" is not working it is still printing as separate graphs. Some tips would help, thank you!
Code below.
clc;
t = linspace(0,1,1000);
yinitial = 5;
r1 = 5;
y1 = yinital * exp(r1*t);
figure, plot(y1)
hold on
r2= 10;
y2 = yinital * exp(r2*t);
figure, plot(y2)

Akzeptierte Antwort

Star Strider
Star Strider am 27 Nov. 2019
You created a second figure object, so the hold call did not apply to it.
You also misspelled ’initial’.
This works:
t = linspace(0,1,1000);
yinitial = 5;
r1 = 5;
y1 = yinitial * exp(r1*t);
figure, plot(y1)
hold on
r2= 10;
y2 = yinitial * exp(r2*t);
plot(y2)
The ‘r1’ plot is barely visible. Use semilogy insatead of plot to make both of them easily seen.
  2 Kommentare
Dominique Davis
Dominique Davis am 27 Nov. 2019
thank you so much!
Star Strider
Star Strider am 27 Nov. 2019
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by