problem with datenum: it does not return the same number for the same date
显示 更早的评论
Hi everybody,
I have a problem with datenum. I have some operations to do on dates. The problem is the following one: for the same date, datenum does not return the same number... that's a problem. My comands:
dnum = datenum(Date(1:n),'dd/mm/yyyy');
dnumCRB = datenum(DateCRB(1:n3),'dd/mm/yyyy');
whos Date DateCRB
Name Size Bytes Class Attributes
Date 1756x1 231572 cell
DateCRB 1756x1 230572 cell
[Date(1:10) DateCRB(1:10)]
ans =
'09/10/2008' '09/10/2008'
'10/10/2008' '10/10/2008'
'13/10/2008' '13/10/2008'
'14/10/2008' '14/10/2008'
'15/10/2008' '15/10/2008'
'16/10/2008' '16/10/2008'
'17/10/2008' '17/10/2008'
'20/10/2008' '20/10/2008'
'21/10/2008' '21/10/2008'
'22/10/2008' '22/10/2008'
[dnum(1:10) dnumCRB(1:10)]
ans =
733661 733661
733662 733690
733663 733691
733666 733694
733667 733695
733668 733696
733669 733697
733670 733698
733673 733701
733674 733702
Do you know what's happened here?
Thank you very much for your help,
Best,
Thomas
回答(1 个)
Azzi Abdelmalek
2015-7-3
编辑:Azzi Abdelmalek
2015-7-3
If we check this, there is no problem
s={'09/10/2008' '09/10/2008'
'10/10/2008' '10/10/2008'
'13/10/2008' '13/10/2008'
'14/10/2008' '14/10/2008'
'15/10/2008' '15/10/2008'
'16/10/2008' '16/10/2008'
'17/10/2008' '17/10/2008'
'20/10/2008' '20/10/2008'
'21/10/2008' '21/10/2008'
'22/10/2008' '22/10/2008'}
d1=s(:,1)
d2=s(:,2)
dnum=datenum(d1,'dd/mm/yyyy')
dnumCRB=datenum(d2,'dd/ mm/ yyyy ')
[dnum dnumCRB]
We can check the problem, if you attach your data file
2 个评论
Campion Loong
2015-7-6
Thomas, You file does not look entirely comma-separated. Some fields have numbers attached followed by semicolons.
Will you also post the code you use to import these to generate the 'Date' & 'DateCRB' variables in the first place?
类别
在 帮助中心 和 File Exchange 中查找有关 Calendar 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!