MATLAB: Plotting multiple lines on same graph

hold on

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)

Best Answer

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.
Related Question