Adapting that code to work with 3D axes:
f = figure;
ax1 = axes(f);
surf(ax1, peaks(50));
grid(ax1, 'off');
axis(ax1, 'tight');
ax2 = axes('Position',ax1.Position,...
'Color','none',...
'YLim',ax1.YLim,...
'XLim',ax1.XLim,...
'ZLim',ax1.ZLim,...
'TickLength',[0 0],...
'YTickLabel',[],...
'XTickLabel',[],...
'ZTickLabel',[],...
'View',ax1.View);
ax2.YTick = linspace(ax1.YLim(1),ax1.YLim(2),5);
ax2.XTick = linspace(ax1.XLim(1),ax1.XLim(2),5);
ax2.ZTick = linspace(ax1.ZLim(1),ax1.ZLim(2),5);
grid(ax2, 'on');
linkprop([ax1, ax2],{'CameraUpVector', 'CameraPosition', 'CameraTarget', 'XLim', 'YLim', 'ZLim'});
Credit to this answer for the code which linked the two sets of axes.
Best Answer