-2

我在matlab中有这段代码。如何关闭带有图形的窗口?我使用这个代码,但它不起作用,为什么?

plot(fig1);%Show chart
hold on;
if button == 1
    close(fig1);
    delete(fig1);
    break;
end;

好的,我更改了代码。但它不起作用。为什么?

fig1 = plot(fig0);
hold on;
if button == 1
    close(fig1);
    break;
end;
4

4 回答 4

1

close command should work.

For instance:

   fig1 = figure();
   close(fig1); 

The mistake is probably somewhere else:

  1. fig1 is not a figure handle.
  2. button is not equal to 1
于 2012-09-20T10:23:36.553 回答
1

You're confusing plot with figure; the latter is for opening a figure, the first is to actually draw something on a figure.

fig_handle = figure;
plot(1:10);
if button==1
    close(fig_handle);
    delete(fig_handle);
    break;
end

But this is likely not going to work, it seems as you want to press a button and then close the previously opened figure. Matlab code is run sequentially, so here the variable button is immediately checked after opening the figure. I think you're looking for a function callback linked to a button.

于 2012-09-20T10:24:37.970 回答
0

You plot the data, which is in fig1. You can not close the data, you need to close the figure

f=figure;
plot(1:10); % example
close(f);
于 2012-09-20T10:23:49.563 回答
0

我想知道您是否需要在图形本身上使用属性。我以前遇到过完全相同的问题,但是您的代码看起来有点可疑。

首先,找出每个变量中的内容:

disp(class(fig1))
disp(ishandle(fig1))
disp(class(fig0))
disp(ishandle(fig0))

如果是句柄,那么据我所知fig0你不能打电话。plot(fig0)如果fig0是一组数据,那么你就是黄金。

顺便说一句,当你调用它时,调用可以由另一段代码设置close()的图形。如果所有变量都检查正常,CloseRequestFcn您可能想尝试。close force顺便说一句,我不确定所有反对票的用途,但您可能需要解释更多背景信息。这对我来说很好,但我想不是每个人都这么宽容。:-)

于 2012-09-20T13:51:06.407 回答