|
* `0 g- k e1 I" g1 w+ A
function test_mouse_track()2 `- {$ G3 W5 R
figure;% H; S1 r" `' E" m2 s- I O
axis([-10,10,0,5]);+ H0 o0 y. B2 _* I! w: E
myfile = fullfile(tempdir,'position.mat');
: B2 z. s Z4 b7 [! F Q Kset(gcf,'WindowButtonDownFcn',@ButttonDownFcn);
+ P: h+ Z* N$ _) h. a+ m5 {( n" z# \: K% K7 E2 `
& X5 P. }: K$ j/ g0 h& ^
% 回调函数
$ J; w4 m9 x e2 Qfunction ButttonDownFcn(src,event)1 V& s7 u) J6 T" }, r
pt = get(gca,'CurrentPoint');
- n, Q; W: ]/ j) Z0 a% {+ }x = pt(1,1);
4 v1 |7 Q9 S3 L! Ky = pt(1,2);
, y# Z! J, ~$ nsave('position.mat','pt','-ascii','-append');; F9 i; i( x) E! T" j4 s: s
fprintf('x=%f,y=%f\n',x,y);: E' C2 @+ F1 N4 N+ Z
9 M1 |9 ^% j* f, W4 u$ a
产生的position.mat文件中就是坐标点数据。 |
|