Using WindowButtonDownFcn callback to track mouse moves in figure

6 visualizaciones (últimos 30 días)
Luc Le Blanc
Luc Le Blanc el 8 de Jun. de 2016
Comentada: Rik el 3 de Nov. de 2017
In Matlab 2013a I must track mouse moves in a figure to let user position vertical markers (timeline limits).
After creating my figure with hfig = figure('Position',rect, ...
I call set(hfig,'WindowButtonDownFcn',@ButtonDown);
and declare
function ButtonDown(hObject, eventdata, handles)
But when I click the mouse in the figure, I get "Undefined function 'ButtonDown' for input arguments of type 'double'. Error while evaluating figure WindowButtonDownFcn".
What is the right function prototype for this callback?

Respuestas (1)

Geoff Hayes
Geoff Hayes el 8 de Jun. de 2016
Luc - the correct signature for this function would be
function ButtonDown(hObject, eventdata)
since you are not supplying any additional parameters when you assign this callback to the WindowsButtonDownFcn
set(hfig,'WindowButtonDownFcn',@ButtonDown);
However, I suspect that isn't the source of the error. Where is this function, ButtonDown, defined relative to your function that assigns it as a callback? Are they both in the same file?
  4 comentarios
Geoff Hayes
Geoff Hayes el 8 de Jun. de 2016
Luc's answer moved here
Yes, the figure is created programmatically.
Thanks for the answer.
Rik
Rik el 3 de Nov. de 2017
If you are not nesting functions, you can use guidata as well to access the handles struct.

Iniciar sesión para comentar.

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by