当我按下' 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);']);
答案 0 :(得分: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));
为我们提供了一个图形窗口,当单击该按钮时它将关闭:
请注意,我已将匿名函数定义为接受&扔掉两个输入。这是因为图形对象回调accept 2 inputs by default,正在执行回调的对象的句柄以及事件数据结构。在这个简单的情况下,我们不需要任何一个,但有很多情况会保留这些信息(例如按钮按回调的事件数据)。