0

我在 GUI 上有一个复选框,可以在实时视频源上绘制一个矩形,但是,当我取消选中它时,我需要该矩形消失或被删除。有谁知道如何做到这一点?

这是我的代码,我试过把东西放进去,但没有任何效果。

function Box(hObject,eventdata)

if (((get(hObject,'Value') == get(hObject,'Max'))))
 % Checkbox is checked-take appropriate action
 hold on;
rectangle('Position',[50,50,100,100],'EdgeColor','r')
else
end
4

1 回答 1

0

您需要保存由函数 rectangle 创建的句柄。然后将此句柄添加到 GUI 的大句柄中,以便在再次调用回调时能够访问它。

所以像这样修改你的功能

function Box(hObject,eventdata,handles)

if (((get(hObject,'Value') == get(hObject,'Max'))))
 % Checkbox is checked-take appropriate action
 hold on;
handles.rectangleSave=rectangle('Position',[50,50,100,100],'EdgeColor','r');
guidata(handles.output,handles);
else
delete(handles.rectangleSave);
end

如果您从未使用过把手,请看这里: http: //www.matlabtips.com/on-handles-and-the-door-they-open/

handle.output 通常将句柄存储到大界面窗口,如下所述:http: //www.matlabtips.com/guide-me-in-the-guide/

于 2012-05-01T06:46:54.090 回答