Clear figure content using clf

Hi all, I have a question about the use of figure() and clf() that I wanted to ask. I am running a code that is calling a certain figure many times within a for loop. I create the figure window outside the loop, and then, anytime I need to plot something (let's say if a certain condition within the foor loop is met) I am calling the figure again and plot my data. Anytime I call the figure, previous data drawn on it are overwritten by new data, just by calling figure() and plot(). So I was wondering, what's the role of clf() if past data are overwritten anyway? What's the difference between just doing figure(); plot() and figure(); clf(); plot(). Thanks a lot Chiara

 採用された回答

Thorsten
Thorsten 2016 年 9 月 20 日

1 投票

If you have open a new figure, it is cleared anyway. So there is no difference between
figure(); plot()
and
figure(); clf(); plot()
If you have you open a figure before a loop and then plot into this figure, the previous content is cleared by default, so you do not need a
figure(3), clf
The clf is useful when you have changed the default behaviour of clearing a figure before each plot using
hold on

2 件のコメント

Chiara
Chiara 2016 年 9 月 20 日
That's what I was thinking, that the previous content is cleared anyway. But actually I just figured that for example, if I want to move from multiple subplots to single plot, I need to call clf(), otherwise it would overwrite only the current subplot window.
Thorsten
Thorsten 2016 年 9 月 21 日
That's true and another case where you need clf.

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

その他の回答 (0 件)

カテゴリ

タグ

質問済み:

2016 年 9 月 20 日

コメント済み:

2016 年 9 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by