Azzera filtri
Azzera filtri

How to extract information from a figure callback functions?

1 visualizzazione (ultimi 30 giorni)
I want to perform actions when the mouse is used inside a figure. I already figured out how to do that thanks to the example in the Matlab help 'Coding Window Button Callback Functions'. What I cannot do is to extract variables values from inside the callback functions - for example this code (which was written by Matt Tearle in an answer to a question):
figure
plot(rand(5))
set(gca,'buttondownfcn',@mybttnfcn)
function mybttnfcn(h,~)
hf = get(h,'parent');
b = get(hf,'selectiontype');
xy = get(gca,'CurrentPoint');
if strcmpi(b,'normal')
text(xy(1,1),xy(1,2),'Left click')
elseif strcmpi(b,'alt')
text(xy(1,1),xy(1,2),'Right click')
else
text(xy(1,1),xy(1,2),'Careful there, crazy man!')
end
Suppose I want to get the value of 'xy' outside of the function 'mybttnfcn', how do I do that? I tried some ideas but without success.
Thank you.

Risposte (0)

Categorie

Scopri di più su Interactive Control and Callbacks in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by