How to extract information from a figure callback functions?

2 visualizaciones (últimos 30 días)
Alon Rozen
Alon Rozen el 2 de Nov. de 2016
Editada: Alon Rozen el 2 de Nov. de 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.

Respuestas (0)

Categorías

Más información sobre Graphics Object Properties en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by