These functions draw horizontal or vertical lines at specified places on the current axes. The axes are automatically held for the drawing of the lines, and restored to their previous 'hold' states afterwards. THe HandleVisibility of the new lines is "off" so that they don't appear on legends. (Incidentally, this also makes them invisible to moveplot.m and addplot.m) Objects with HandleVisibility set to off can be "found" by setting the root object's "ShowHiddenHandles" property to "on". Also, if an output argument is specified, the function will return the handle to the otherwise 'hidden' object.
Further arguments allow the user to set the linetype and color of the line (default is 'r:'), and to add labels. For example:
h = vline(42,'g','The Answer')
will return a handle to a vertical line at x=42 on the current axes, colored green, and with a text label "The Answer" on the axes close to the line, and in the same color of the line.
Very helpful and simple. Thanks!
I just made a minor change to the 'vline' function (to make the labels vertical):
This really saves me a lot of time. Matlab should put these two small programs into the standard library.
14 Oct 2008
Thanks - this saves a lot of time and trouble!
24 Sep 2008
Great tool, thanks for submitting!
21 May 2008
12 Nov 2007
Thanks a lot.It's very nice.
22 Jun 2007
Works great for linear axes. The location of the label is off if it has logrithmic axes.
09 May 2007
Awesome! At least sizeof(long) times better than doing it the standard way.
06 Jun 2006
Very nice. My only (minor) comment would be it might be nice to control the location of the annotation text. I do agree that this is functionality that should have always been in matlab.
By the way, if anyone is worried, it works on a mac also. This is not system specific code.
11 Apr 2006
Great tool - one enhancement would be to allow for restricting the range of the lines.
20 Mar 2006
Should be Matlab standard functions.
20 Nov 2005
03 Oct 2005
perfect for what i needed.
14 Jul 2005
11 Apr 2005
When I use VLINE, and later resize the axis with AXIS, vertical line's limits remain unadjusted.
04 Feb 2005
Nice handy function. Good job
03 Feb 2005
20 Jan 2005
14 Jan 2005
Handy lil' time saver.
17 Nov 2004
This is an excellent, easy to use tool to add a reference line in your plot figure. Can also be customized for color and linetypes. Good Job.
27 Oct 2004
This function meets the common need for drawing simple horz and vert lines on plots. Very nice addition to my tools; should be incorporated into future plot revision. Thank you for taking the time to share your work.
20 Oct 2004
thanks for writing this.
It's amazing how matlab runtime library did not have such a function built-in.
21 Sep 2004
Excellent, easy to use, very effective, good work!
01 Apr 2004
fast and easy!
23 Jan 2004
it's very handy and useful!!! Thanks:)
16 Nov 2001
Very nice, but I get two extra data elements in the plot legend? Is there a way around that?