%% Display Subset of Lines in Legend
% Plot five lines and return the chart line objects from the plot function.

x = linspace(0,3*pi);
y1 = sin(x);
p1 = plot(x,y1);

y2 = sin(x - pi/4);
hold on
p2 = plot(x,y2);

y3 = sin(x - pi/2);
p3 = plot(x,y3);

y4 = sin(x - 3*pi/4);
p4 = plot(x,y4);

y5 = sin(x - pi);
p5 = plot(x,y5);
hold off

%
% Add a legend for the first and last lines, p1 and p5.

legend([p1,p5],'sin(x)','sin(x-\pi)')

% Copyright 2015 The MathWorks, Inc.