MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   MATLAB论坛 (https://www.labfans.com/bbs/forumdisplay.php?f=6)
-   -   记录鼠标点击的位置 (https://www.labfans.com/bbs/showthread.php?t=2642)

Narumi 2008-04-27 11:37

记录鼠标点击的位置
 
set(gcf,'WindowButtonDownFcn','CC=get(gca,''currentpoint'')');这个命令可以得到鼠标点击的一个位置坐标,但如何将一系列点击的坐标存到数组里?试过很多方法都不行,如set(gcf,'WindowButtonDownFcn',['CC(i)=get(gca,''currentpoint''),','i=i+1,']);。不知该如何解决?谢谢!:lovely:

shiqiang 2008-04-27 11:50

% 这是一个交互式的图形程序,随着你的鼠标点击相应的坐标,它会记下你点击的位置及点击的先后顺序,当你点解取点结束后,它会绘制出% 你去点所走过的路线。
function mouse
h0=figure('toolbar','none',...
'position',[200 150 450 250],...
'name','实例14');
axis([0 10 0 10]);
hold on
x=[];
y=[];
n=0;
disp('单击鼠标左键点取需要的点,当你点击鼠标右键时取点结束,并取得最后一个点。');
but=1;
while but==1
[xi,yi,but]=ginput(1);
plot(xi,yi,'bo')
n=n+1;
disp('单击鼠标左键点取下一个点');
x(n,1)=xi;
y(n,1)=yi;
end
t=1:n;
ts=1:0.1:n;
xs=spline(t,x,ts);
ys=spline(t,y,ts);
plot(xs,ys,'r-');
hold off
这是我写过的一个程序,你可以借鉴一下。


所有时间均为北京时间。现在的时间是 10:03

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.