马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
%要求在当前坐标轴下,用鼠标拖动划线。按鼠标左键出现+,之后拖动鼠标,松开点即为结束点,可多次划线。问题是划线的起点是原点,不能多次划线。源程序:<BR>function ex_draw(arg)<BR>global DRAW_HL<BR>if nargin==0<BR> arg='ex_line'<BR>end<BR>if isstr(arg)<BR> clear all<BR> Hf=gcf;<BR> set(Hf,'pointer','corssh','backingstore','off',...<BR> 'windowbuttondownfcn','ex_draw(1)');<BR> figure(Hf);<BR>elseif arg==1<BR> fp=get(gca,'currentpoint');<BR> set(gca,'userdata',fp(1,1:2));<BR> set(gcf,'windowbuttonmotionfcn','ex_draw(2)',...<BR> 'windowbuttonupfcn','ex_draw(3)')<BR>elseif arg==2<BR> cp=get(gca,'currentpoint');cp=cp(1,1:2);<BR> fp=get(gca,'userdata');<BR> H1=line('xdata',[fp(1);cp(1)],'ydata',...<BR> [fp(2);cp(2)],'erasemode','xor','color',...<BR> 'r','linestyle','-','clipping','off');<BR> if ~isempty(DRAW_HL)<BR> delete(DRAW_HL)<BR> end<BR> DRAW_H1=H1;<BR>elseif arg==3<BR> set(gcf,'pointer','arrow',...<BR> 'backingstore','on',...<BR> 'windowbuttondownfcn','',...<BR> 'windowbuttonmotionfcn','',...<BR> 'windowbuttonupfcn','')<BR>set(gca,'userdata',[]);<BR>set(DRAW_HL,'erasemode','normal')<BR>key=waitforbuttonpress;<BR>if key<BR> gtext('finish');<BR> return;<BR>esle<BR> ex_draw;<BR>end<BR>end |