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!