How many times a date appears in an array

1 次查看(过去 30 天)
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