No License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Rubberband Line

4.7 | 11 ratings Rate this file 12 Downloads (last 30 days) File Size: 1.13 KB File ID: #1552 Version: 1.0

Rubberband Line



Draws a rubber band line and returns the x y coordinates of the end points.

| Watch this File

File Information


Function to draw a rubberband line and return the start and end points. Usage: [p1,p2]=rbline; or [p1,p2]=rbline(h); where h is an axis handle. Click the mouse in the plot to define the start point. A rubberband line is drawn between the start point and the current point until the mouse is clicked again. The start point, p1, and the end point, p2, are returned. The figure UserData is not available while this function is running but is restored after it ends.


This file inspired Muscle Fascicle Tracking Ultrasound.

MATLAB release MATLAB 6.0 (R12)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (11)
13 Jul 2011 Matthew Schroeder

Great code!

30 Jan 2009 Matt J

Matt J (view profile)

Nice. I had a problem where, after drawing the rubberband line, subsequently plotted figures would not paint over the previous figure. Adding "hold off" to the end of the code seems to have fixed this.

07 Mar 2007 Jared Goor

Very simple if you remember to input the axes and not the image. Works great and easily outputs the endpoints. Code is simple to adjust to your needs.

29 Nov 2006 Bill Korpsus

nice routine. I was trying to find something like that, it seems there's a similar routine at least in Matlab 7, it's called gline. You may find it useful as well.

17 Mar 2006 Calvin Mao

Excellent work!
I have added "drawnow" in the callback function, cuz it seems Matlab 7 does not redraw when erasemode is "normal". Or, you can change the erasemode of the line to "xor" without adding "drawnow".

05 Jan 2005 Markus Karlsson

Wonderful! Just what I was looking for! I modified it for interactive region growing, thanks! (also added drawnow at the end)

07 Sep 2004 John Petty

Had a problem with the line drawing in R14 on a XP machine. added drawnow; at the end of wbmf function and works well now

13 Aug 2004 Sam Richardson

Just what I needed! I have modified it to show a rectangle using the two points as opposing corners instead of connecting the dots. THANKS!!!

01 Feb 2004 manbir sodhi

11 Jun 2003 Brian Katz

I was about to try and figure out how to write this then I thought I would check here first. Even used the name I would have used. Works very well. The window motion function is very clever.

08 May 2003 Chuck Hayden

simple program, easy to use, taught me something new. easily made mods to work in my app. thanks!

Contact us