MATLAB: Plotyy with sync yaxis tics on both sides

plotyy

Matlab does provide plotyy for plotting two graphs with different yaxis, but does not sync the tics. Also matlab provides no possibility to switch of the tics on the opposite side. so far my knowledge.
Now I want to plot two lines whith completely unrelated y-data. Currently the tics of left and right axis are not in sync and the plot therefore looks messed up.
So I need a solution to sync the tics on he y-axis on both sides. ( A problem also dicusses with the same topic here.)
My actual plot function is this one
[AX,H1,H2] = plotyy(xaxis, ydata1, xaxis, ydata2);
A solution found on the thread linked above is the following one, but I do not see how to integrate it with my plot function (the plot is empy after I execute this code)
% dummy axes for the box and background color
ax0 = axes;
set (ax0, 'Box', 'on', 'Color', 'white', 'XTick', [], 'YTick', []);
% first axes for left y-axis
ax1 = axes ('Position', get (ax0, 'Position'));
set (ax1, 'Box', 'off', 'Color', 'none', 'YAxisLocation', 'left');
% second axes for right y-axis assuming common x-axis controlled by ax1
ax2 = axes ('Position', get (ax0, 'Position'));
set (ax2, 'Box', 'off', 'Color', 'none', 'XTick', [], 'YAxisLocation', 'right');
Any hint welcome.

Best Answer

Matlab allows you to switch the ticks on both axes. plotyy is creating two overlapping axes on the figure. When you execute this command:
[AX,H1,H2] = plotyy(xaxis, ydata1, xaxis, ydata2);
AX returns a 2x1 double array with the two axis handles. If you want to adjust the ticks and tick labels for the right axis, the command would be:
set(AX(2),'YTick',<your array>)
set(AX(2),'YTickLabel',<your cell array>)