MATLAB: Are the dates not aligned correctly when I use the DATEAXIS function

MATLAB

Execute the following code and note the year labels are not aligned correctly. I would like to know if this is a bug in DATEAXIS.
vd = datenum('01-Jun-1991'):datenum('30-Jun-2001');
dy_3M_vol = abs(sin(0.01*vd).*(randn(size(vd))))+.0001;
figure(1)
plot(vd,dy_3M_vol);
axis([ datenum(1991,01,01) datenum(2001,12,31) 0 ceil(max(dy_3M_vol)*10)/10]);
dateaxis('x');
xlabel('Date');
ylabel('3M yield volatility (yearly, percentage)');

Best Answer

The DATEAXIS function is performing as expected, as it does not have the feature of placing the year labels at the beginning of the year. This is because the DATEAXIS function simply replaces axis tick labels with date labels.
The axis tick labels are originally in numeric format and so do not actually represent beginnings of the years. So, after the labels have been replaced they do not actually represent the beginnings of the years.
If you want the year labels to mark the beginnings of the years, a better function to use is DATETICK. For more information regarding this function enter
doc datetick
at the MATLAB Command Prompt.