How to count number of days within datetime array

조회 수: 7 (최근 30일)
Louise Wilson
Louise Wilson 2020년 7월 8일
댓글: Louise Wilson 2020년 7월 9일
I have a timetable which spans a year. The intervals between the datetimes varies from one minute to ten minutes. I am interested in finding out how many days contain any data at all. I tried using histogram but this returns an empty bin on days in which there was no data collected, and so conflates days where there was data collected but the values were 0, and data where there was no data collected.
numberdays=histogram(timetable.DateTime,'BinMethod','day');
This seems like it should be simple but I am sorry I can't figure it out!

채택된 답변

Kanupriya Singh
Kanupriya Singh 2020년 7월 9일
Since your previous attempts are returning you empty data for days that are not in your datetime array, you could calculate the number of days that have any data by using this function-
nnz(x)
This will return you the number of non-zero elements in the array.
  댓글 수: 2
Louise Wilson
Louise Wilson 2020년 7월 9일
Thanks Kanupriya-I have actually since done this before you replied and it's the only method I have found to work!
Louise Wilson
Louise Wilson 2020년 7월 9일
[Tally,~,bin]=histcounts(tt,'BinMethod','day');
days=nnz(Tally);

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

madhan ravi
madhan ravi 2020년 7월 8일
Use retime() with 'daily' 'count' .
  댓글 수: 1
Louise Wilson
Louise Wilson 2020년 7월 8일
Thanks for your response Madhan. I tried this:
countdays=retime(Kawau_counts,'daily','count');
but it does the same as my attempt above. It lists all days between the first datetime and last datetime in my timetable, and so creates rows for datetimes that never existed in my timetable in the first place.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Timetables에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by