How to stop figure windows from popping up when there is no data to plot.

3 ビュー (過去 30 日間)
Tanner Avery
Tanner Avery 2021 年 3 月 16 日
回答済み: Jeff Miller 2021 年 3 月 16 日
I have a code that creates figures using multiple loops. There are conditional statements within my code that dictate whether a plot is created or not based on certian conditions. My problem is that even when the conditions are such that no plot is created an empty figure window still pops up as if a plot was created. This is leading to a lot of clutter as my program is outputting dozens of figure windows when only 2-3 are needed. Below is an example of my problem. When h = 0 the program outputs a plot for Figure 2 and a blank window for figure 1 (see attached photo). What method could I use to not have the window for figure 1 appear at all when h=0?
vmin=1;
vmax = 20;
h = 0;
f1=figure('Name','Figure x');
f2=figure('Name','Figure y');
while vmin < vmax
v = vmin;
x=v;
y=v/2;
if h == 1
set(0,'CurrentFigure',f1);
hold on
plot(x,y,'or');
title ('figure 1')
hold off
end
y2=v*2;
set(0,'CurrentFigure',f2);
hold on
plot(x,y2,'ok');
title ('figure 2')
hold off
vmin=vmin+1;
end

採用された回答

Jeff Miller
Jeff Miller 2021 年 3 月 16 日
The commands
f1=figure('Name','Figure x');
f2=figure('Name','Figure y');
make the two windows pop up, so you must change your code so that those commands are only executed in cases where you actually want the windows. Not sure what you intend, but it looks like maybe you want the 'figure' commands inside the 'if' statement.

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by