%% Add Legend to Specific Axes
% Create a figure with two subplots and return the two Axes objects, ax1 and ax2. Plot random data in each subplot. Add a legend to the upper subplot by specifying ax1 as the first input argument to legend.

y1 = rand(3);
ax1 = subplot(2,1,1); 
plot(y1)

y2 = rand(5);
ax2 = subplot(2,1,2); 
plot(y2)

legend(ax1,{'Line 1','Line 2','Line 3'})

% Copyright 2012 The MathWorks, Inc.