Matlab GUI:设置当前轴创建一个新图

时间:2014-03-01 18:10:07

标签: matlab matlab-guide

我创建了一个包含3个轴的GUI:axes1axes2axes3。我有一个类SP,其构造函数我传递三个轴,如下所示:

a=SP(handles.axes1,handles.axes2,handles.axes3)

该课程类似于

class SP < handles
   properties
      axes1
      axes2
      axes3
   end
   methods
      function A=SP(axes1,axes2,axes3)
          A.axes1=axes1;
          A.axes2=axes2;
          A.axes3=axes3;
          axes(A.axes1);
          rectangle('Position',[randn,randn,randn,randn]);
          axes(A.axes2);
          rectangle('Position',[randn,randn,randn,randn]);
          axes(A.axes3);
          rectangle('Position',[randn,randn,randn,randn]);
      end

我写了一个计时器功能

function timerfcn1(~,~,A)
    axes(A.axes1);
    rectangle('Position',[randn,randn,randn,randn]);
    axes(A.axes2);
    rectangle('Position',[randn,randn,randn,randn]);
    axes(A.axes3);
    rectangle('Position',[randn,randn,randn,randn]);
end

我的问题是在初始化期间,即当我调用构造函数时,矩形被绘制在GUI窗口中。但是,每当timerfcn1运行时,它都会创建一个新图形,并在其中绘制矩形。

之前我曾经使用过类似的东西,然后它曾经工作过。

1 个答案:

答案 0 :(得分:0)

最有可能的是,它与您未显示的部分代码中的可见性(或缺少)相关。为了保证矩形到达您想要使用的轴,

rectangle('Position',[...],'Parent',A.axes1)

在此之前,您还应该使用

检查句柄是否仍然存在
if ishandle(A.axes1)
...
end