Filter löschen
Filter löschen

'ButtonDownFcn' not working on first click

1 Ansicht (letzte 30 Tage)
Jeremy
Jeremy am 6 Jul. 2016
Bearbeitet: Jeremy am 7 Jul. 2016
Hi,
I'm trying to write a simple code to drag lines on a plot, and then get the X values. It worked well for some time, but I can't get it to work anymore; so, I tried the following tutorial code, that doesn't work either:
function test
f = figure;
aH = axes('Xlim',[0 1],'Ylim',[0 1]);
h = line([0.5 0.5],[0 1],'ButtonDownFcn',@startDragFcn);
set(f,'WindowButtonUpFcn',@stpDragFcn);
function startDragFcn(varargin)
set(f,'WindowButtonMotionFcn',@draggingFcn);
end
function draggingFcn(varargin)
pt = get(aH,'CurrentPoint');
set(h,'XData',pt(1)*[1,1]);
end
function stopDragFcn(varargin)
set(f,'WindowButtonMotionFcn','');
end
end
I can't click-drag-release; however, if I click and release, I can drag, but obviously can't stop (except if I click outside the plot area on the figure).
I tried without great hope 'hold all', to modify 'Interruptible'/'Hittest' properties, but nothing works and I'm out of ideas...
Thank you for your help

Akzeptierte Antwort

Jeremy
Jeremy am 7 Jul. 2016
Bearbeitet: Jeremy am 7 Jul. 2016
Even though my solution is not really elegant, solved.
%added in the stardrag function:
set(linehandle,'HitTest','off');
%added in the stopdrag function:
set(linehandle,'HitTest','on');

Weitere Antworten (0)

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by