Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function draw_wire
- % Click the left mouse button to define a point
- % Drag the mouse to draw a line to the next point and
- % left click again
- % Right click the mouse to stop drawing
- figure('WindowButtonDownFcn',@wbdcb)
- axis1 = axes('DrawMode','fast');
- axis ([1 10 1 10])
- function wbdcb(src,evnt)
- if strcmp(get(src,'SelectionType'),'normal')
- [x,y,str] = disp_point(axis1);
- hl = line('XData',x,'YData',y,'Marker','.');
- text(x,y,str,'VerticalAlignment','bottom');drawnow
- set(src,'WindowButtonMotionFcn',@wbmcb)
- elseif strcmp(get(src,'SelectionType'),'alt')
- set(src,'WindowButtonMotionFcn','')
- [x,y,str] = disp_point(axis1);
- text(x,y,str,'VerticalAlignment','bottom');drawnow
- end
- function wbmcb(src,evnt)
- [xn,yn,str] = disp_point(axis1);
- xdat = [x,xn];
- ydat = [y,yn];
- set(hl,'XData',xdat,'YData',ydat);
- end
- end
- function [x,y,str] = disp_point(axis1)
- cp = get(axis1,'CurrentPoint');
- x = cp(1,1);y = cp(1,2);
- str = ['(',num2str(x,'%0.3g'),', ',num2str(y,'%0.3g'),')'];
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment