%% Synchronize and Change x-Axis Limits
% Create a figure with two subplots and plot some data. Then, synchronize the x-axis limits in both plots. Note that the y-axis limits do not synchronize.

ax1 = subplot(2,1,1);
x1 = linspace(0,6);
y1 = sin(x1);
plot(x1,y1)

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

linkaxes([ax1 ax2],'x');

%
% Set the x-axis limits for the second subplot. The two sets of axes are linked, so the x-axis limits in the first subplot also change.

ax2.XLim = [1.5 3.5];

% Copyright 2019 The MathWorks, Inc.