How many times a date appears in an array

조회 수: 1 (최근 30일)
Max
Max 2015년 10월 10일
답변: the cyclist 2015년 10월 10일
I am given
7 10 2001 16 2 15 5
7 10 2001 20 18 0 5
7 10 2001 24 10 5 14
7 10 2001 26 15 2 1
7 10 2001 27 13 2 9
31 3 2002 1 9 0 6
1 4 2002 4 19 10 3
2 4 2002 5 30 11 12
3 4 2002 14 17 6 8
3 4 2002 21 29 8 3
4 4 2002 25 6 5 6
5 4 2002 2 24 2 0
The first column is the date second column is the month and third the year. For example 7 10 2001 is the 7th of October 2001. What would I need to write to show how many dates appeared in between and including 31 3 2002 and 3 4 2002. So from 31 3 2002 and 3 4 2002 there are 5 total dates (both 31 3 2002 and the two times 3 4 2002 come up are both included) So I would like the answer to be 5. Thanks for the help.

채택된 답변

the cyclist
the cyclist 2015년 10월 10일
Here's one way:
D = [
7 10 2001 16 2 15 5
7 10 2001 20 18 0 5
7 10 2001 24 10 5 14
7 10 2001 26 15 2 1
7 10 2001 27 13 2 9
31 3 2002 1 9 0 6
1 4 2002 4 19 10 3
2 4 2002 5 30 11 12
3 4 2002 14 17 6 8
3 4 2002 21 29 8 3
4 4 2002 25 6 5 6
5 4 2002 2 24 2 0
]
dateNumber = datenum(D(:,3),D(:,2),D(:,1))
dateRangeBegin = datenum(2002,3,31)
dateRangeEnd = datenum(2002,4,3)
numberOfDatesInRange = sum(dateNumber>=dateRangeBegin & dateNumber<=dateRangeEnd);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Time Series Objects에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by