I googled near and far, but couldn't get an example of how you associate a callback to the click event in matlab. Can someone show me an example?
Define the WindowButtonDownFcn
of your figure callback using the set command and an @callbackfunction
tag.
Like so:
function mytestfunction()
f=figure;
set(f,'WindowButtonDownFcn',@mytestcallback)
function mytestcallback(hObject,~)
pos=get(hObject,'CurrentPoint');
disp(['You clicked X:',num2str(pos(1)),', Y:',num2str(pos(2))]);
You can also pass extra variables to callback functions using cell notation:
set(f,'WindowsButtonDownFcn',{@mytestcallback,mydata})
If you're working with uicontrol objects, then it's:
set(myuicontrolhandle,'Callback',@mytestcallback)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With