Using WindowButtonDownFcn callback to track mouse moves in figure
7 views (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
Geoff Hayes
on 8 Jun 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 Comments
Geoff Hayes
on 8 Jun 2016
Luc's answer moved here
Yes, the figure is created programmatically.
Thanks for the answer.
Rik
on 3 Nov 2017
If you are not nesting functions, you can use guidata as well to access the handles struct.
See Also
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!