Plotting multiple lines on same graph

35 ビュー (過去 30 日間)
Dominique Davis
Dominique Davis 2019 年 11 月 26 日
コメント済み: Star Strider 2019 年 11 月 27 日
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)

採用された回答

Star Strider
Star Strider 2019 年 11 月 27 日
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 件のコメント
Dominique Davis
Dominique Davis 2019 年 11 月 27 日
thank you so much!
Star Strider
Star Strider 2019 年 11 月 27 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by