MATLAB: How to change the font in the legend? (possible bug)

fontlegendMATLAB

The script below contains two methods of creating a legend. The first one, figure 1, gives the behaviour I want: the font is size 14, Times New Roman. However, in the second example, the font remains in the default typeface and size.
The only difference is the way the legend is initialized: in the first example the legend is initialized using "lgnd = legend(_);" with only one output varaible, whilst in the second example the legend is initialized using "[lgnd,icons,plots,txt] = legend(_);" with four output variables.
How do I change the font in the second example?
I have MATLAB 2015b.
% FIGURE 1 LEGEND IN TIMES NEW ROMAN
figure(1)
% generate some plots

plot([1 1 1 1],1:4,'.','MarkerSize',2)
hold on
plot([2 2 2 2],1:4,'.','MarkerSize',2)
plot([3 3 3 3],1:4,'.','MarkerSize',2)
plot([4 4 4 4],1:4,'.','MarkerSize',2)
hold off
lgnd = legend('1','2','3','4');
set(lgnd,'FontSize',14);
set(lgnd,'FontName','Times New Roman');
% FIGURE 2 LEGEND IN DEFAULT FONT
figure(2)
% generate some plots
plot([1 1 1 1],1:4,'.','MarkerSize',2)
hold on
plot([2 2 2 2],1:4,'.','MarkerSize',2)
plot([3 3 3 3],1:4,'.','MarkerSize',2)
plot([4 4 4 4],1:4,'.','MarkerSize',2)
hold off
[lgnd,icons,plots,txt] = legend('1','2','3','4');
set(lgnd,'FontSize',14);
set(lgnd,'FontName','Times New Roman');
Edit: Added the pictures as attachments to illustrate.

Best Answer

When you create a legend with four outputs in R2014b or later, it gets created differently, with an ItemText property that contains the text handles; if you create with one output then that property is empty and the text is handled internally somehow.
You can handle this together by using
temp = [lgnd; lgnd.ItemText];
set(temp, 'FontSize', 14)
set(temp, 'FontName', 'Times New Roman')
If the legend was built without the text output then lgnd.ItemText will be empty and temp will just be the lgnd object and in that case setting its properties works. If the legend was built with the text output then setting the lgnd properties appears to be ignored but does not hurt, and setting the text objects from the ItemText property works.