Code covered by the BSD License  

Highlights from
Date to Decimal Day of Year

4.0

4.0 | 6 ratings Rate this file 34 Downloads (last 30 days) File Size: 1.62 KB File ID: #18316

Date to Decimal Day of Year

by

 

14 Jan 2008 (Updated )

Convert a vector of MATLAB serial dates to decimal days since the start of the year.

| Watch this File

File Information
Description

This function calculates the decimal day of the year of the input vector of dates. The dates must be in MATLAB serial date format.

For example, for datestr(now), MATLAB produces: "18-Jan-2008 14:33:27". The output of this function, called "date2doy" yields-
date2doy(now): "18.60662".

There are two outputs, the decimal date (can be a vector), and the fraction of the year completed by that date. From the example above, the fraction of the year is: "0.0481"

This function is very fast, and is ideal for embedding in larger applications that call date2doy many times.

Acknowledgements

This file inspired Day Of Year To Matlab Date and Deseason.

MATLAB release MATLAB 7.4 (R2007a)
Other requirements Should work in all recent versions of MATLAB.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (8)
27 Aug 2013 Chad Greene  
21 Jun 2012 Radar  
22 May 2009 Ashley

I just submitted a doy2date.m. Thanks to both Anthony and James for the inspiration.

22 May 2009 Ashley

I am giving this a higher rating now because it is named properly and the new code can handle vectors. Thanks!

28 Apr 2009 Anthony Kendall

Ashley,
Not sure why FEX didn't have the date2doy. Should have been updated last January 18th, but something must have gone wrong there. I resubmitted the function.

27 Apr 2009 Ashley

The file that I downloaded is called date2julian when it should be called date2doy according to the file information.

I was looking for a function to convert from MATLAB serial date format to a day of year (1-365) and this one does that. It is just that the file name and documentation is misleading witht he mention of Julian dates.

18 Jan 2008 Anthony Kendall

Thanks, James, for your comments. You've helped me to make the code clearer and
faster.

I completely rewrote the function and resubmitted it.

I don't think it's as trivial as you suggest.

Also, Julian Day is very often in the Environmental Sciences used to refer to the day of the year. Terminology like that, essentially jargon, can have different definitions from field to field. But, to avoid confusion I've gone ahead and changed it to "doy" as you suggested.

14 Jan 2008 James Tursa

I did not give this submission a good rating for the following reasons:

1) This routine basically returns the day of the year, not a Julian day. The term Julian day should be reserved for the astronomical definition of days since noon Universal Time (UT) Monday, January 1, 4713 BC. So the name of the function and the description should be something like datenum2doy.m, or the like. Descriptions like "... Julian days since the start of the year ... " are ambiguous and should be removed.

2) This routine takes a datenum type of variable as an input, but the variable name used by the author is date, and date is an existing MATLAB function name. This may be confusing to users. The name of the input date variable should be changed.

3) The functionality provided by this routine is fairly simple. For example, the following few MATLAB lines essentially do the same thing for the day-of-year calculation and are just as fast:

function doy = datenum2doy(dn)
dv = datevec(dn);
dv(:,2:end) = 0;
doy = dn - datenum(dv);
end

In summary, I gave this submission a low score because of the simple functionality provided and the misuse of the Julian day terminology. The author did comment his code, which is why I gave it a 2 instead of a 1. (you should always give people who comment their code *some* reward).

James Tursa

Updates
28 Apr 2009

Submitted modified file to FEX as detailed in file description.

Contact us