Your code did a great job after it just switched some statements! The trick is to first increase the number of ticks and then call the datetick.
With 30 samples, the labels are, of course, too crowded for any worthy plot. As a solution, I downloaded xticklabelrotate from a file sharing.
Here is the modified code. I used dummy y data so that others can play with a workable example.
t = 1:1257; % Days 1:1257 inclusive. 20100101 to 20130611 y = t.^2; x = datenum(2009, 12, 31) + t; str = datestr(x, 'mmm yyyy'); plot(x, y); NumTicks = 30; L = get(gca,'XLim'); set(gca,'XTick',linspace(L(1),L(2),NumTicks)) datetick('x','mmm yyyy','keeplimits', 'keepticks') xticklabel_rotate; set(gca,'XMinorTick','on','YMinorTick','on')
The result looks something like this:

For any real world application, never forget to label the axes! :-)
EDIT
Using the above code to evenly distribute the number of elements over a given period of time is a bad idea, especially when combined with a date format that gives the date very βrudeβ.
Instead, you should put your ticks at the beginning of the month, otherwise a random viewer will be misled.
Instead, I suggest using this code:
t = 1:1257; % Days 1:1257 inclusive. 20100101 to 20130611 y = t.^2; x = datenum(2009, 12, 31) + t; str = datestr(x, 'mmm yyyy'); plot(x, y); tick_locations = datenum(2009,10:1:54,1); set(gca,'XTick',tick_locations) datetick('x','mmm yyyy','keeplimits', 'keepticks') xticklabel_rotate;
Here, tags are delayed at 1-month intervals between October 2009 and 54 months later, which runs until June 2013. (Numbers found by trial and error.)

Ticks are now always at the beginning of the month, which means that the space between them is slightly different from month to month, as it should be. (28 days for FEB-MAR, 31 days for MAR-APR)