필터 지우기
필터 지우기

decimal day

조회 수: 16 (최근 30일)
ricco
ricco 2011년 11월 4일
답변: Moyo Ajayi 2019년 10월 24일
Any ideas of how to convert year, day of year(1:365), and time (i.e. 17:59 is given as 1759) to decimal day.
I've already changed the time into hours and minutes so now have: year; day(1:365); hour(1:24); min(1:60) But how would i go about converting this to decimal day?
thanks

답변 (5개)

Walter Roberson
Walter Roberson 2011년 11월 4일
Not taking leap-years and leap seconds in to account:
(year * 365 + day) + (hour / 24 + minute / (24*60))

Fangjun Jiang
Fangjun Jiang 2011년 11월 4일
Year=2011;
Day=250;
Hour=23;
Minute=35;
D=datenum(Year,1,1)+Day-1;
[Year,Month,Day]=datevec(D);
D=datenum(Year,Month,Day,Hour,Minute,0)
  댓글 수: 1
Walter Roberson
Walter Roberson 2011년 11월 4일
This is probably more reliable than the version I gave.

댓글을 달려면 로그인하십시오.


Andrei Bobrov
Andrei Bobrov 2011년 11월 4일
for array d
d =[ 2002 190 17 16
2003 345 7 14
2004 233 17 41
2003 350 17 51
2007 88 2 21];
out = datenum([d(:,1), zeros(size(d,1),2)])+d(:,2)+sum(bsxfun(@rdivide,d(:,3:end),[24 60]),2);

ricco
ricco 2011년 11월 4일
All of these seem to work i.e. they give the same answer, but i though that decimal day would be given in the form of day 1.23344 etc, these values are in the range of 7.325572215277777e+05? what does this refer to?
thanks
  댓글 수: 1
Fangjun Jiang
Fangjun Jiang 2011년 11월 4일
That is the number of days since Jan 0, year 0000. See the help document of datenum, datestr, datevec. Also, try the following
datestr(0)
datestr(1)
now
datestr(now)

댓글을 달려면 로그인하십시오.


Moyo Ajayi
Moyo Ajayi 2019년 10월 24일
A simple way to do this is by using dec_doy. You will not have to worry about leap year and instead. I am still working on formatting the repository, which will have more useful functions. However, for now, it should be helpful for your problem. All you need to do before hand is convert your dates into datetime objects by using the datetime() function.
Example:
>> dt = datetime(2019, 10, 23, 21, 50, 05, 123);
>> decimal_doy = dec_doy(dt)
decimal_doy =
296.9098

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by