How do you convert Month/Day to Julian Day?
11 次查看(过去 30 天)
显示 更早的评论
I need to convert [yyyy MMM dd (hh mm ss)] into 3-digit (decimal) julian day, but every function I try takes numbers 1-31 (for dd "day") and doesn't increment the month, so julian day output is always less than 32. I need the ability to use the "MMM" portion...
I do not have major toolboxes (i.e. one solution requires the Financial Toolbox, not viable for me)
There is a solution I have by adding monthly # of days, but I'm not sure how to account for LEAP years (when # of days in February changes).
Output should be 001-365 (with floating decimal)
0 个评论
采纳的回答
更多回答(2 个)
dpb
2014-7-29
>> dn=datenum(2008,1,[1:2:400].',0,0,0); % make up some date nums
>> d=dn-dn(1); % get the day from beginning
>> [d(1:10) d(180:189)] % display some results
ans =
0 358
2 360
4 362
6 364
8 366
10 368
12 370
14 372
16 374
18 376
>>
NB: datenum handles leap years transparently--2008 was selected specifically because it was a leap year; note that day 366 did show up.
This is cumulative over years as can be observed.
A handy little utility routine is
function is=isleapyr(yr) % returns T for given year being a leapyear
is=(datenum(yr+1,1,1)-datenum(yr,1,1))==366;
Put in m-file isleapyr.m and place on matlabpath
0 个评论
Steven Lord
2016-11-10
D = datetime('today')
DOY = day(D, 'dayofyear')
Since 2016 is a leap year and today is November 10th, DOY should be (and is) 315 according to Wikipedia.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!