如何阻止matlab图弹出

时间:2016-01-20 07:16:49

标签: matlab popup matlab-figure

for m=1:10;
    pause(0.2)
    h1=figure(1);
    set(h1,'Position',[200 200 600 500]);
    pause(0.2)
    h2=figure(2);
    set(h2,'Position',[600 200 600 500]);
end

当我运行上面的代码时,两个数字会像下面一样交替出现。

enter image description here

enter image description here

我想停止这个弹出属性并在整个迭代期间保持位置,如下所示。

enter image description here

我怎样才能更改此属性?

提前谢谢。

我添加了一个代码。在这段代码中,两个数字不断闪烁。 我想要做的就是停止这种眨眼。

clear all
close all
clc
%%patch1%%
x1=[-2 0 0 -2];
y1=[-1 -1 1 1];
z1=[0 0 0 0];
a=patch(x1,y1,z1,'green');
c=patch(x1,y1,z1,'green');

%%patch2%%
x2=[0 2 2 0];
y2=[-1 -1 1 1];
z2=[0 0 0 0];
b=patch(x2,y2,z2,'red');
d=patch(x2,y2,z2,'red');

%h1=figure(1),grid on

    for k=0:pi/10:10*pi
        delete([a b])
        figure(1),grid on
        a=patch(x1,y1,z1+[-0.1*sin(k) 0.3*sin(k) 0.3*sin(k) -0.1*sin(k)],'green');
        b=patch(x2,y2,z2+[0.3*sin(k) -0.1*sin(k) -0.1*sin(k) 0.3*sin(k)],'red');
        axis([-2.5 2.5 -1.5 1.5 -0.5 0.5])

        pause(0.05)
        delete([c d])
        figure(2),grid on
        c=patch(x1,y1,z1+[-0.3*sin(k) 0.05*sin(k) -0.05*sin(k) -0.4*sin(k)],'green');
        d=patch(x2,y2,z2+[0.05*sin(k) 0.4*sin(k) 0.3*sin(k) -0.05*sin(k)],'red');
        axis([-2.5 2.5 -1.5 1.5 -0.5 0.5])

        pause(0.05)

    end

3 个答案:

答案 0 :(得分:3)

你应该避免在循环中调用数字!线h1=figure(1);h2=figure(2);不断切换焦点。每当您想在图形窗口中放置某些内容时,请对某些轴对象'parent',h1使用'parent',ax1选项对或ax1。避免致电figure。我建议您只使用figure来创建图形窗口。

例如,不是通过创建图形和轴对象(figure(1);image(img);)来启动h1=figure(1);ax1=axes('Parent',h1);,而是在想要更新图中的图像时使用image(img,'Parent',ax1);。 / p>

答案 1 :(得分:2)

使用''Parent'' property对象的patch指定要axes的情节,而无需figure来更新current axes

使用您的示例:

f(1) = figure;
f(2) = figure;
ax(1) = axes('Parent', f(1));
ax(2) = axes('Parent', f(2));

for ii = 1:length(ax)
    axis(ax(ii), [-2.5 2.5 -1.5 1.5 -0.5 0.5]);
    grid(ax(ii), 'on');
    hold(ax(ii), 'on');
end

%%patch1%%
x1=[-2 0 0 -2];
y1=[-1 -1 1 1];
z1=[0 0 0 0];
a=patch(x1,y1,z1,'green', 'Parent', ax(1));
c=patch(x1,y1,z1,'green', 'Parent', ax(2));

%%patch2%%
x2=[0 2 2 0];
y2=[-1 -1 1 1];
z2=[0 0 0 0];
b=patch(x2,y2,z2,'red', 'Parent', ax(1));
d=patch(x2,y2,z2,'red', 'Parent', ax(2));

for k=0:pi/10:10*pi
    delete([a b])
    a=patch(x1,y1,z1+[-0.1*sin(k) 0.3*sin(k) 0.3*sin(k) -0.1*sin(k)],'green', 'Parent', ax(1));
    b=patch(x2,y2,z2+[0.3*sin(k) -0.1*sin(k) -0.1*sin(k) 0.3*sin(k)],'red', 'Parent', ax(1));

    pause(0.05)
    delete([c d])
    c=patch(x1,y1,z1+[-0.3*sin(k) 0.05*sin(k) -0.05*sin(k) -0.4*sin(k)],'green', 'Parent', ax(2));
    d=patch(x2,y2,z2+[0.05*sin(k) 0.4*sin(k) 0.3*sin(k) -0.05*sin(k)],'red', 'Parent', ax(2));
    pause(0.05)
end

for ii = 1:length(ax)
    hold(ax(ii), 'off');
end

另外,您还可以通过修改补丁对象的'XData', 'YData', and 'ZData'来更新补丁,而不是删除&每个循环创建补丁对象。这通常更有效。

使用主要for循环作为示例(assumes R2014b or newer):

for k=0:pi/10:10*pi
    a.ZData = z1+[-0.1*sin(k) 0.3*sin(k) 0.3*sin(k) -0.1*sin(k)];
    b.ZData = z2+[0.3*sin(k) -0.1*sin(k) -0.1*sin(k) 0.3*sin(k)];
    pause(0.05)

    c.ZData = z1+[-0.3*sin(k) 0.05*sin(k) -0.05*sin(k) -0.4*sin(k)];
    d.ZData = z2+[0.05*sin(k) 0.4*sin(k) 0.3*sin(k) -0.05*sin(k)];
    pause(0.05)
end

答案 2 :(得分:1)

不要在每次迭代中添加和删除每个补丁,而应考虑首先在循环外创建它们,然后在循环内更改它们:

%%patch1%%
x1=[-2 0 0 -2];
y1=[-1 -1 1 1];
z1=[0 0 0 0];

%%patch2%%
x2=[0 2 2 0];
y2=[-1 -1 1 1];
z2=[0 0 0 0];

figure(1),grid on
a=patch(x1,y1,z1,'green');
b=patch(x2,y2,z2,'red');
axis([-2.5 2.5 -1.5 1.5 -0.5 0.5])

figure(2),grid on
c=patch(x1,y1,z1,'green');
d=patch(x2,y2,z2,'red');
axis([-2.5 2.5 -1.5 1.5 -0.5 0.5])

for k=0:pi/10:10*pi
    set(a, 'ZData', z1+[-0.1*sin(k) 0.3*sin(k) 0.3*sin(k) -0.1*sin(k)]);
    set(b, 'ZData',z2+[0.3*sin(k) -0.1*sin(k) -0.1*sin(k) 0.3*sin(k)]);

    pause(0.05)
    set(c, 'ZData', z1+[-0.3*sin(k) 0.05*sin(k) -0.05*sin(k) -0.4*sin(k)]);
    set(d, 'ZData', z2+[0.05*sin(k) 0.4*sin(k) 0.3*sin(k) -0.05*sin(k)]);

    pause(0.05)
end