【问题标题】:Matlab GUI:Setting Current Axes creates a new figureMatlab GUI:设置当前轴创建一个新图形
【发布时间】:2014-03-01 18:10:06
【问题描述】:

我创建了一个带有 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 运行时,它都会创建一个新图形并在其中绘制矩形。

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

【问题讨论】:

  • 我无法运行这段代码!!请修改代码以便我们能够运行
  • 编辑了代码。但是我如何显示 gui

标签: matlab matlab-guide


【解决方案1】:

这很可能与处理您未显示的部分代码中的可见性(或缺乏)有关。为保证矩形到达您要使用的轴,

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

在此之前,您还应该检查句柄是否仍然存在使用

if ishandle(A.axes1)
...
end

【讨论】:

    猜你喜欢
    • 2014-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-23
    • 2015-07-31
    • 2014-02-13
    • 1970-01-01
    • 2018-11-30
    相关资源
    最近更新 更多