MATLAB: Plotyy: how to use ‘datetick’ on both axis

MATLABplotyy

I used 'plotyy' to plot some data on left and right y-axis. Both the data have xaxis in date format. Therefore, at first, I plotted the y data against date-numbers; then I a using 'datetick' to convert my x-axis ticks to date format. But, it seems that 'datetick' does not allow using axis-objects, so it only converts one of the axis in date format. The other axis is left in date-number format. I am using following code:
figure;
Ax=plotyy(s_xaxis,streamflow,p_xaxis,prcp);
datetick('x','mm/dd/yyyy')
set(Ax(1),'linewidth',2);
set(Ax(2),'Ydir','reverse','xAxisLocation','Top');
Please suggest a way so that both the axis can be converted to date format.

Best Answer

datetick does accept axes handle as the first argument.
datetick(Ax(1), 'x', 'mm/dd/yyyy')
datetick(Ax(2), 'x', 'mm/dd/yyyy')
On the other hand, for plotyy there should only be one visible x axis, so it might just be a matter of selecting the right one.