LEGENDTITLE adds a title inside the legend axes.
LEGENDTITLE(LEGH,TITLESTR) adds the title TITLESTR to the legend LEGH
LEGENDTITLE(TITLESTR) adds the title to the current legend in the current axes.
LEGENDTITLE(...,Param,Val) sets the specified properties for the text object.
H = LEGENDTITLE(...) returns the handle for the text object used to create the title string.
By default, the legend title uses the same font as the legend, but with a bold font weight.
legh = legend('Random 1','Random 2','Random 3','Random 4','Random 5');
It seems the problem can be avoided calling the saveas function instead of clicking Save As from the figure window's File menu (which internally calls hgexport).
saving it to jpg, png or pdf messes it up, haven't tried any other formats.
It does not work properly if you save the image as .eps.
Just what I needed. Works fine in R2009a (64-bit version).
The function worked fine but will not allow the legend to be placed outside the axes.
With R2008a it works perfectly.
It puts the title inside the box legend in bold.
(Default title property of legend put a title outside of the legend box).
The function doesn't work in Matlab 14!!
Another option please!
Didn't work: error in line 68: Function 'mrdivide' is not defined for values of class 'cell'.
I personally liked Jos' solution better, but this is supposed to put the title INSIDE the legend! And anyway, thanks for bringing up the issue! ;-)
Unfortunately this nice function doesn't work with R14.
Although this looks nice when first applied to a plot, it gets messed up as soon as I resize the plot... :-( This is more important than it might initially seem, since I use the exportfig.m tools to export / print my figures and this always involves a resize.
Nice function, and not redundant, it adds the title _inside_ the legend box
Redundant! This does the job already:
>> h = legend(...) ;
>> set(get(h,'title'),'String','Legend Title')
Excellent function! Very easy to use ... thank you!
Update to work in R14 and later.
Change description to indicate that title is inserted inside legend box, in response to review. The reviewer's code puts a title outside the legend axes.
Inspired: Add a title to a legend
Create scripts with code, output, and formatted text in a single executable document.