hold on producing separate graphs

12 ビュー (過去 30 日間)
Lucy
Lucy 2022 年 12 月 11 日
編集済み: Voss 2022 年 12 月 13 日
hold on
figure
x = I
y1 = 4*I.^20
hold on
plot(x,y1)
figure
x = I
y2 = 4*I.^1
hold on
plot(x,y2)
figure
x = I
y3 = 4*I.^0.3
hold on
plot (x,y3)
Here is my code for the three lines I want to plot on the same graph, however it is producing 3 separate graphs, I wondered how I can edit this to ensure it plots the three lines on one graph?
Thank you

採用された回答

VBBV
VBBV 2022 年 12 月 11 日
I = 1:10;
figure
x = I
x = 1×10
1 2 3 4 5 6 7 8 9 10
y1 = 4*I.^2
y1 = 1×10
4 16 36 64 100 144 196 256 324 400
hold on
plot(x,y1)
% figure
x = I
x = 1×10
1 2 3 4 5 6 7 8 9 10
y2 = 4*I.^1
y2 = 1×10
4 8 12 16 20 24 28 32 36 40
hold on
plot(x,y2)
% figure
x = I
x = 1×10
1 2 3 4 5 6 7 8 9 10
y3 = 4*I.^0.3
y3 = 1×10
4.0000 4.9246 5.5616 6.0629 6.4826 6.8471 7.1712 7.4643 7.7327 7.9810
hold on
plot (x,y3)
  2 件のコメント
Lucy
Lucy 2022 年 12 月 11 日
Perfect, thank you!
VBBV
VBBV 2022 年 12 月 11 日
Its better to use subplot when you have values on lines which differ by significantly high
I = 1:10;
subplot(311)
x = I
x = 1×10
1 2 3 4 5 6 7 8 9 10
y1 = 4*I.^20 % this ^ 20 is huge number !
y1 = 1×10
1.0e+20 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0032 0.0461 0.4863 4.0000
plot(x,y1)
y2 = 4*I.^1
y2 = 1×10
4 8 12 16 20 24 28 32 36 40
subplot(312)
plot(x,y2)
y3 = 4*I.^0.3
y3 = 1×10
4.0000 4.9246 5.5616 6.0629 6.4826 6.8471 7.1712 7.4643 7.7327 7.9810
subplot(313)
plot (x,y3)

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

その他の回答 (1 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2022 年 12 月 11 日
編集済み: KALYAN ACHARJYA 2022 年 12 月 11 日
Remove all "figure" statements, also one hold on is sufficient.
Same Figures:
x = I
y1 = 4*I.^20
hold on
plot(x,y1)
x = I
y2 = 4*I.^1
plot(x,y2)
x = I
y3 = 4*I.^0.3
plot (x,y3)

カテゴリ

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

タグ

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by