MATLAB: Plotting data extending one year

plottingtime

In the following example I have a data set that extends over a section of two years.
time = datenum('2008-04-17 02:00'):datenum('2009-11-24 12:27');
dateV = datevec(time);
for i = 1:length(time);
DOY(i) = time(i) - datenum(dateV(i,1),0,0);
end
data = rand(length(time),1);
plot(time,data);
In this example I have calculated the day of year from the Julian date, but I cannot plot the data against day of year because the day of year will be the same for both years (if that makes sense). So, I have plotted the data against Julian date and would like to know of a way to alter the x axis to show the day of year calculated in 'DOY'.

Best Answer

try this is code
t = datenum('2008-04-17 02:00'):datenum('2009-11-24 12:27');
data = randi(150,numel(t),1);
DOY = t(:) - datenum(year(t(:)),0,1);
plot(t,data);
set(gca,'XTick',floor(t(1:50:end))','XTickLabel',floor(DOY(1:50:end)))