Hi Jonas,
Thanks for you help. Actually your suggestions gave me the right push in the direction to make it work :). I used an "addlistener" in my function, and this way I added two listeners for each axes, which are activated whenever Y limits of either left or right axes are changed (for example from command line).
function test_limits()
figure;
ax(1) = axes('color','none');
ax(2) = axes('color','none','yaxislocation','right','xcolor','none');
ax(1).YLim = [0 1];
ax(2).YLim = [0 2];
addlistener(ax(1), 'YLim','PostSet', @(~,~)(adjust_right_limits(ax)));
addlistener(ax(2), 'YLim','PostSet', @(~,~)(adjust_left_limits(ax)));
axes(ax(1))
end
function adjust_right_limits(ax)
ax(2).YLim = ax(1).YLim*2;
end
function adjust_left_limits(ax)
ax(1).YLim = ax(2).YLim/2;
end
Best Answer