Counting days by month

7 次查看(过去 30 天)
hi,
i have a 100x11 char array with dates (e.g. '03-Jan-2006'). how can i create an array with the number of days in each unique month that appear in my date array. (e.g. if i have two days in january 2006, then i want it to return 2). any help would be appreciated. thx in advance.
DB

采纳的回答

Andrei Bobrov
Andrei Bobrov 2017-10-22
编辑:Andrei Bobrov 2017-10-22
Here A - your array "100x11 char array with dates (e.g. '03-Jan-2006')"
z = datetime(A);
T = table(datetime(z,'F','MMM-uuuu'),eomday(year(z),month(z)),'v',{'date','days'});
  4 个评论
dan berkowitz
dan berkowitz 2017-10-23
Thank you! I didn't know about the ymd function! Appreciate your help.
Andrei Bobrov
Andrei Bobrov 2017-10-23
[y,m] = ymd(z);
or
[y,m] = datevec(z);

请先登录,再进行评论。

更多回答(1 个)

KL
KL 2017-10-22
编辑:KL 2017-10-22
It's better to change your char array into datetime vector
dt_array = datetime(char_array,'InputFormat','dd-MMM-yyyy')
and then you can use
numOfDays = nnz(dt_array.Month==your_month)

类别

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