%% Add Legend to Current Axes
% Plot two lines and add a legend to the current axes. Specify the legend labels as input arguments to the legend function.

x = -pi:pi/20:pi;
y1 = sin(x);
plot(x,y1)

hold on 
y2 = cos(x);
plot(x,y2,'--')
legend('sin(x)','cos(x)')
hold off

% If you add or delete charts from the axes, the legend updates accordingly. To delete the legend, use legend('off').
% Copyright 2012 The MathWorks, Inc.