%% Link Axes So They Rotate Simultaneously
% Link properties of two axes so that rotating one axes automatically rotates the other.
% Create a figure with two axes, and store the axes objects as ax1 and ax2. Add plots to both axes.

figure
ax1 = subplot(2,1,1);
[X1,Y1,Z1] = peaks;
surf(X1,Y1,Z1)

ax2 = subplot(2,1,2);
[X2,Y2,Z2] = peaks(10);
surf(X2,Y2,Z2)

%
% Link the CameraPosition and CameraUpVector properties of the axes and return the link object handle. Then, rotate one of the axes by calling the view function. Rotating one axes automatically rotates the other in the same manner.

hlink = linkprop([ax1,ax2],{'CameraPosition','CameraUpVector'});
view(ax2,[-90 0])

%
% Link an additional property by passing the link object handle and the property name to addprop. For example, link the GridColor property, and then change the grid color for one of the axes. The grid color for the other axes also changes.

addprop(hlink,'GridColor')
ax2.GridColor = 'red';

% Copyright 2020 The MathWorks, Inc.