GUI 鼠标点击图像响应事件

function click_plot()

 

img = imread('1.png');

imshow(img);

set(gcf,'WindowButtonDownFcn',{@ButttonDownFcn});  %鼠标点击响应函数

 

% 回调函数

function ButttonDownFcn(src,event)

pt = get(gca,'CurrentPoint'); 

x = round(pt(1,1));  %鼠标点击点坐标

y = round(pt(1,2));

 

*************************************************

%%传递函数到回调函数中

function click_plot()

 

img = imread('1.png');

matri = input('Please input 2 variables:/nlag, length/n');

lag = matri(1);

length= matri(2);

imshow(img);

set(gcf,'WindowButtonDownFcn',{@ButttonDownFcn,img,lag,length});  %鼠标点击响应函数

 

% 回调函数

function ButttonDownFcn(src,event,img,lag,length)

[height,width] = size(img);

pt = get(gca,'CurrentPoint'); 

x = round(pt(1,1));  %鼠标点击点坐标

y = round(pt(1,2));

你可能感兴趣的:(function,input,plot,variables)