MATLAB: Unable to add title to legend

I tried to give a title to the legend on my plot but the error of Error using title (line 27) Incorrect number of input arguments
So I tried using the example given on the Matlab website:
x = -pi:pi/20:pi;
y1 = sin(x);
plot(x,y1)
hold on
y2 = cos(x);
plot(x,y2)
hold off
lgd = legend('sin(x)','cos(x)');
title(lgd,'My Legend Title')
And I got the same error. I would like some help with this.

Best Answer

legends do not have titles. Axes have titles.