%% Create Subplots and Link Their Axes
% Create three subplots and link their _x_-axes
% and _y_-axes so that they are always in sync.

% Copyright 2015 The MathWorks, Inc.


%%
% First, create a figure with three subplots. Plot data in each subplot.
figure
ax1 = subplot(2,2,1);
x1 = linspace(0,6);
y1 = sin(x1);
plot(x1,y1)

ax2 = subplot(2,2,2);
x2 = linspace(0,10);
y2 = sin(2*x2);
plot(x2,y2)

ax3 = subplot(2,2,[3,4]);
x3 = linspace(0,16);
y3 = sin(6*x3);
plot(x3,y3)

%%
% Now link the axes for the three subplots using the |linkaxes| function. Pass
% the string |'xy'| as an input argument to the function to link both the
% _x_-axes and _y_-axes. The |linkaxes| function uses the limits from the
% first axes passed to it.
linkaxes([ax1,ax2,ax3],'xy')

%%
% Panning or zooming into one of the subplots displays the same range of
% data in the other two subplots. To remove the linking, use
% |linkaxes([ax1,ax2,ax3]),'off'|.