How to extract information from a figure callback functions?

2 vues (au cours des 30 derniers jours)
Alon Rozen
Alon Rozen le 2 Nov 2016
Modifié(e) : Alon Rozen le 2 Nov 2016
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.

Réponses (0)

Catégories

En savoir plus sur Graphics Object Properties 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