Filter only specific month from date serial number
5 次查看(过去 30 天)
显示 更早的评论
Hi guys, I got a column with a date serial number and I would like to filter only the month of march. What is the coding for that?
0 个评论
采纳的回答
Peter Perkins
2017-3-16
Unless you're using a version prior to R2014b, use datetimes:
>> dn = 736696 + 90*rand(10,1)
dn =
736755.016662924
736699.214051072
736772.421637528
736780.059392298
736757.086163937
736764.196611752
736762.881922131
736731.300431758
736754.993010116
736711.406801903
>> d = datetime(dn,'ConvertFrom','datenum')
d =
10×1 datetime array
01-Mar-2017 00:23:59
04-Jan-2017 05:08:14
18-Mar-2017 10:07:09
26-Mar-2017 01:25:31
03-Mar-2017 02:04:04
10-Mar-2017 04:43:07
08-Mar-2017 21:09:58
05-Feb-2017 07:12:37
28-Feb-2017 23:49:56
16-Jan-2017 09:45:47
>> (d.Month == 3)
ans =
10×1 logical array
1
0
1
1
1
1
1
0
0
0
Prior to 14b, use datevec.
0 个评论
更多回答(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!