%% Specify Axes for Legend
% Create a figure with two subplots and return the two axes
% handles, |ax1| and |ax2|. Plot random data in each subplot. 

% Copyright 2015 The MathWorks, Inc.


rng default % initialize random number generator
y1 = rand(3);
y2 = rand(5);

figure
ax1 = subplot(2,1,1); % upper subplot
plot(y1)

ax2 = subplot(2,1,2); % lower subplot
plot(y2)

%%
% Add a legend to the upper subplot by passing its axes handle to |legend|. 

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