Only one Figure in plot

5 ビュー (過去 30 日間)
Ranjan Rao
Ranjan Rao 2016 年 3 月 23 日
コメント済み: Ced 2016 年 3 月 24 日
I have a loop like this For I=1:5 and my entire code in this loop. There are 9 figures in this loop. Since the loop is executed 5 times there will be 45 figures. How to make it such that there were only 9 figures? The figures cannot be placed outside the loop
  1 件のコメント
Adam
Adam 2016 年 3 月 23 日
Tell the code explicitly which figure to plot in (or which axes to plot on, the axes being linked to the figure) and use
hold( hAxes, 'on' )
for an axes hand hAxes to ensure subsequent plots are added rather than replace the existing plot.

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

回答 (1 件)

Ced
Ced 2016 年 3 月 23 日
You can specify which figure you want to plot in bringing up the figure before (either through it's number or the figure handle).
In order to keep old lines, use "hold on" (or set NextPlot to 'add')
e.g.
figure(1)
plot(x1,y1); % plot first
hold on % keep rest
figure(2)
plot(x2,y2); % plot something in a different figure
hold on; % keep that too for later
figure(1) % back to first figure
plot(x3,y3);
etc.
  2 件のコメント
Ranjan Rao
Ranjan Rao 2016 年 3 月 23 日
So there will be only 9 figures even if the loop is executed say 10 or 20 times
Ced
Ced 2016 年 3 月 24 日
There will be as many figures as you define. Just try it.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by