Filter löschen
Filter löschen

How many times a date appears in an array

1 Ansicht (letzte 30 Tage)
Max
Max am 10 Okt. 2015
Beantwortet: the cyclist am 10 Okt. 2015
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.

Akzeptierte Antwort

the cyclist
the cyclist am 10 Okt. 2015
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);

Weitere Antworten (0)

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by