How do you convert Month/Day to Julian Day?
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Tom W
el 29 de Jul. de 2014
Respondida: Steven Lord
el 10 de Nov. de 2016
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 comentarios
Respuesta aceptada
Más respuestas (2)
dpb
el 29 de Jul. de 2014
>> 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 comentarios
Steven Lord
el 10 de Nov. de 2016
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 comentarios
Ver también
Categorías
Más información sobre Dates and Time en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!