Borrar filtros
Borrar filtros

'ButtonDownFcn' not working on first click

1 visualización (últimos 30 días)
Jeremy
Jeremy el 6 de Jul. de 2016
Editada: Jeremy el 7 de Jul. de 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

Respuesta aceptada

Jeremy
Jeremy el 7 de Jul. de 2016
Editada: Jeremy el 7 de Jul. de 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');

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by