How to extract information from a figure callback functions?
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Properties 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!