>> dt = between(datetime(2005,11,26),datetime(2006,1,1),'days')
dt =
36d
>> (2006-1860)/4
ans =
36.5
>> y = [datetime(1860,1,0) datetime(1860,2,28) + calyears(0:5)]
y =
Columns 1 through 6
31-Dec-1859 28-Feb-1860 28-Feb-1861 28-Feb-1862 28-Feb-1863 28-Feb-1864
Column 7
28-Feb-1865
>>
>> d = caldiff(y,'days')
d =
59d 366d 365d 365d 365d 366d
>> d = caldays(d)
d =
59 366 365 365 365 366
>>
>> hasLeapDay = (d == 366)
hasLeapDay =
0 1 0 0 0 1
>> adjust = cumsum(hasLeapDay)
adjust =
0 1 1 1 1 2
>> breakPoints = [1 cumsum(d)+1]
breakPoints =
1 60 426 791 1156 1521 1887
>> netcdfDay = [(58:61) (58:61)+365 (58:61)+2*365 (58:61)+3*365]
netcdfDay =
Columns 1 through 7
58 59 60 61 423 424 425
Columns 8 through 14
426 788 789 790 791 1153 1154
Columns 15 through 16
1155 1156
>> realDay = netcdfDay + discretize(netcdfDay,breakPoints,adjust)
>> realDay =
Columns 1 through 7
58 59 61 62 424 425 426
Columns 8 through 14
427 789 790 791 792 1154 1155
Columns 15 through 16
1156 1157
>> datestr(realDay + datenum([1860,1,0]))
ans =
27-Feb-1860
28-Feb-1860
01-Mar-1860
02-Mar-1860
27-Feb-1861
28-Feb-1861
01-Mar-1861
02-Mar-1861
27-Feb-1862
28-Feb-1862
01-Mar-1862
02-Mar-1862
27-Feb-1863
28-Feb-1863
01-Mar-1863
02-Mar-1863
1 Comment
Campion Loong (view profile)
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/266143-loss-of-precision-with-netcdf-time-when-using-datenum#comment_340383
Sign in to comment.