Matlab 如何从图像';s按钮关闭事件处理程序?
我在初始化中有以下代码Matlab 如何从图像';s按钮关闭事件处理程序?,matlab,event-handling,scope,Matlab,Event Handling,Scope,我在初始化中有以下代码 im = imread('Image02.tif'); figure(); imagesc(im); colormap(gray); [hImage hfig ha] = imhandles(gcf); set(hImage,'ButtonDownFcn',@clickInImage); 单击图像功能如下所示 function clickInImage(s,e) pt=get(gca,'Currentpoint'); x=pt(1,1); y=p
im = imread('Image02.tif');
figure(); imagesc(im); colormap(gray);
[hImage hfig ha] = imhandles(gcf);
set(hImage,'ButtonDownFcn',@clickInImage);
单击图像功能如下所示
function clickInImage(s,e)
pt=get(gca,'Currentpoint');
x=pt(1,1);
y=pt(1,2);
...
我的问题:如何在
clickInImage
功能中访问图像im
?我无法使用全局变量。您可以使用以下方法检索回调中的图像:
img = get(s, 'CData');
否则,将回调设为主GUI函数中的嵌套函数,这样您就可以访问其所有父工作区:
function myGUI()
img = imread('coins.png');
figure
hImg = imagesc(img); colormap(gray)
set(hImg,'ButtonDownFcn',@clickInImage);
function clickInImage(src,evt)
%# here you can access `img` directly ...
img;
end
end