Effacer les filtres
Effacer les filtres

'ButtonDownFcn' not working on first click

1 vue (au cours des 30 derniers jours)
Jeremy
Jeremy le 6 Juil 2016
Modifié(e) : Jeremy le 7 Juil 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

Réponse acceptée

Jeremy
Jeremy le 7 Juil 2016
Modifié(e) : Jeremy le 7 Juil 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');

Plus de réponses (0)

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by