%% Synchronize x-Axis Limits and Display Shared Axis Labels
% Create two plots in a 2-by-1 tiled chart layout. Synchronize the x-axis limits by calling the linkaxes function.

x1 = linspace(0,20,100);
y1 = sin(x1);
x2 = 3:17;
y2 = rand(1,15);

% Create plots.
t = tiledlayout(2,1);
ax1 = nexttile;
plot(ax1,x1,y1)
ax2 = nexttile;
stem(ax2,x2,y2)

% Link the axes. Add title and labels.
linkaxes([ax1,ax2],'x');

%
% Create shared x- and y-axis labels by passing t to the xlabel and ylabel functions. Remove the x-axis tick labels from the top plot by calling the xticklabels function. Then minimize the space between the plots by setting the TileSpacing property of t to 'compact'.

xlabel(t,'Input')
ylabel(t,'Output')
xticklabels(ax1,{})
t.TileSpacing = 'compact';

% Copyright 2019 The MathWorks, Inc.