MATLAB: When I use PLOTYY why do additional axes get created in MATLAB 7.8 (R2009a)

MATLAB

I am using PLOTYY in my GUI because I would like to display two plots with different y-axes. I use the syntax:
plotyy([handles.axes1 handles.axes2],x1dat,y1dat,x2dat,y2dat)
However, when I do this, the right plot does not plot to handles.axes2. Instead it plots to a newly created axes.

Best Answer

As per the documentation for PLOTYY, ignores when an array of axes handles are passed as the first argument to PLOTYY, any handle after the first element is ignored. PLOTYY always generates new axes for the right hand axes.
Instead you may plot directly to the axes and then use the LINKAXES command to link the figures:
H1s = semilogx(handles.axes1,freqGHz,s11dB);
H2s = semilogx(handles.axes2,freqGHz,s11ph);
linkaxes([handles.axes1 handles.axes2],'x')
set(handles.axes2,'Color','none','YAxisLocation','right')