X = linspace(-2*pi,2*pi,20);
Y = 5*sin(X)./X;
plot(X,Y,'x-')
axis equal
waitforbuttonpress;
Cp = get(gca,'CurrentPoint');
Xp = Cp(2,1);
Yp = Cp(2,2);
[dp,Ip] = min((X-Xp).^2+(Y-Yp).^2);
Xc = X(Ip);
Yc = Y(Ip);
str1 = sprintf('\\leftarrow クリックした場所');
str2 = sprintf(['最も近いデータ点: (%f,%f) \\rightarrow'],Xc,Yc);
ht(1) = text(Xp,Yp,str1,'Clipping','off');
ht(2) = text(Xc,Yc,str2,'Clipping','off', 'HorizontalAlignment','right');
set(ht,'FontSize',8,'Color','red')
x=0:.01:2*pi;
y=sin(x);
h=plot(x,y);
hc=uicontextmenu;
hm=uimenu('parent',hc);
set(h,'uicontextmenu',hc);
set(gcf,'windowbuttondownfcn', ...
'pt=get(gca,''currentpoint'');set(hm,''label'',[num2str(pt(1,1)) '', '' num2str(pt(1,2))])')