我试图在轴上绘制一条线,点击时只要按下鼠标按钮,当按钮释放时,线将停止跟随。简而言之,根据点击和拖动将图形上的一条线重新定位到新的位置。WindowButtonUpFcn问题:它为什么不释放?
我已经能够开始让线跟随鼠标指针,问题是得到WindowButtonUpFcn停止跟随鼠标线。即如何关闭WindowButtonMotionFcn?
这是代码。这很粗糙,因为它只是一个小型测试程序,所以不要批评太多。
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
x = 0:.1:10;
y = zeros(size(x))+.5;
line(x,y, 'Tag', 'newLine');
set(findobj('Tag', 'newLine'),'ButtonDownFcn',@button_down)
end
function button_down(src,evnt)
% src - the object that is the source of the event
% evnt - empty for this property
set(src,'Selected','on')
set(gcf, 'WindowButtonMotionFcn', @button_motion);
end
function button_motion(src, evnt)
h = findobj('Tag', 'axes1');
pos = get(h, 'CurrentPoint');
disp(pos);
hndl = findobj('Tag', 'newLine');
delete(hndl);
x = 0:.1:10;
y = zeros(size(x))+pos(3);
line(x,y, 'Tag', 'newLine');
set(gcf, 'WindowButtonUpFcn', @button_up);
end
function button_up(src, evnt)
%What to do here?
end
制定出很好,谢谢你gnovice。 – Michael 2010-07-04 03:23:47
+1为完整的解决方案,并弥补缺乏接受。 – Jonas 2010-07-04 19:05:20