I have the following code for producing a plot of data that extends two years in terms of day of year:
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);
set(gca,'XTick',floor(time(1:50:end))','XTickLabel',floor(DOY(1:50:end)))
Could someone suggest a method for ensuring the ticks on the xaxis are for day numbers that are multiples of 10 i.e. 110, 160 etc.
ADDED SECTION:
DateTime=datestr(datenum('2007-01-01 00:00','yyyy-mm-dd HH:MM'):1/24:...
datenum('2011-12-31 23:00','yyyy-mm-dd HH:MM'),...
'yyyy-mm-dd HH:MM');
time = datenum(DateTime,'yyyy-mm-dd HH:MM');
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);
mydays = ~mod(floor(DOY),40); %true for days that are multiples of 10
set(gca,'XTick',floor(time(mydays))','XTickLabel',floor(DOY(mydays)))
Error using set
Values must be monotonically increasing
This can be fixed by removing floor, i.e.
set(gca,'XTick',time(mydays),'XTickLabel',floor(DOY(mydays)))
But it generates the labels in bold, why is this?
You can generate an index to days that are multiples of N using the
modfunction. This function returns you the remainder after dividing a number by N.In your case having each multiple of 10 would lead to too many labels on the x-axis, so maybe try multiple of 40, which produces the following:
.
Finally, if you want to change the axis labels so that it is no longer in bold, you can use:
or similarly you can alter its size and font:
EDIT: corrected typo in previous code, and added note on altering label font