Search code examples
matlabaxes

How to partially apply linkaxes?


Say I have four plots h1-h4 and want to link all their x-axes. For that I can use linkaxes([h1 h2 h3 h4], 'x'). However, in addition I want to link h1 and h3's y-axes (and also h2's to h4's). Now when I use linkaxes([h1 h3], 'y') the x-axes linking is lost. How can both linkings be achieved at the same time?


Solution

  • Lines 73 and 74 of linkaxes are:

    %# Remove any prior links to input handles
    localRemoveLink(ax)
    

    I suggest you create a new function, myLinkaxes, via "Save As...", where you comment out line 74. Even better, myLinkaxes could accept an additional input argument "keep", which is used in an if-clause around lines 73 and 74, i.e. if keep is 1, localRemoveLink is not called.

    This should work if you separately link x and y-axes, but if you use the 'xy' argument before or after, there might be trouble.