当我按下'X‘关闭弹出窗口时,会得到这样的错误。
下面是我遇到的错误:
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);']); 发布于 2017-09-19 20:06:54
您已经将回调定义为字符向量,在MATLAB在基本工作空间中进行评估。中没有定义PopupWindow。您可以使用匿名函数作为回调。
例如:
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));提供一个图形窗口,当单击按钮时,该窗口将关闭:

注意,我已经定义了匿名函数来接受和丢弃两个输入。这是因为图形对象回调默认情况下接受2个输入、其回调正在执行的对象的句柄以及事件数据结构。在这种简单的情况下,我们不需要这两种方法,但是在许多情况下,这些信息将被保留(例如,按下回调按钮的事件数据)。
https://stackoverflow.com/questions/46308641
复制相似问题