2017-09-19 62 views
1

当我按下'X'关闭弹出窗口时,出现这样的错误。错误使用删除()MATLAB GUI

这里是我的错误:

Undefined function or variable 'PopupWindow'. 

Error while evaluating UIControl Callback 

这里是我使用的代码:

function PopupWindow = alertBox(figg,position,showtext,titlebar); 

    PopupWindow = uipanel('Parent',figg,'Units','pixels','Position',position,... 
      'BackGroundColor',CYAN,'BorderType','beveledout','ButtonDownFcn','','Visible','on'); 

    uicontrol('Parent',PopupWindow,'Units','pixels','Style','PushButton','String','X',... 
        'Position',[position(3)-margin+1 position(4)-margin+1 margin-2 margin-2],'Callback',... 
        ['delete(PopupWindow);']); 

回答

2

您已经定义了你的回调为特征向量,这MATLAB evaluates in the base workspace其中没有定义PopupWindow。您可以改用anonymous function作为回拨。

例如:

fig = figure(); 
a = uicontrol('Parent', fig, 'Style', 'Pushbutton', 'Units', 'Normalized', ... 
       'Position', [0.1 0.1 0.8 0.8], 'String', 'Delete Figure', ... 
       'Callback', @(h,e)delete(fig)); 

给了我们一个数字窗口将关闭按钮被点击时:我已经定义了匿名函数接受&抛

yay

注去掉两个输入。这是因为图形对象回调accept 2 inputs by default,其回调正在执行的对象的句柄和事件数据结构。在这种简单的情况下,我们不需要任何一个,但是在许多情况下这些信息将被保留(例如,按钮回叫的事件数据)。

+0

这非常明确和有用。非常感谢你! –