How can i clear a plot that drawn in a subplot?

250 ビュー (過去 30 日間)
Le Dung
Le Dung 2017 年 11 月 23 日
Hi everyone! I use subplot to draw two plots. How can i delete any plot on each subplot? Why i use clf(p1), plot on second subplot is deleted? My code:
subplot(2,1,1);
hold on
x1=(0:0.01:10);
y1=sin(x1);
p1=plot(x1,y1);
subplot(2,1,2)
hold on
x1=(0:0.01:10);
y2=sin(x1)+cos(x1);
p2=plot(x1,y2,'Color','r');
clf(p2)
clf(p1)

採用された回答

Image Analyst
Image Analyst 2017 年 11 月 23 日
Use cla() instead of clf() and clear the axes instead of deleting the curve.
h1 = subplot(2,1,1);
hold on
x1=(0:0.01:10);
y1=sin(x1);
p1=plot(x1,y1);
h2 = subplot(2,1,2)
hold on
x1=(0:0.01:10);
y2=sin(x1)+cos(x1);
p2=plot(x1,y2,'Color','r');
cla(h2)
cla(h1)
  2 件のコメント
Le Dung
Le Dung 2017 年 11 月 23 日
Thank you so much.
Luis Humberto Niño Alvarez
Luis Humberto Niño Alvarez 2019 年 10 月 4 日
Thanks

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by