How to compute the frequency of hourly/daily observation?

조회 수: 2 (최근 30일)
aa
aa 2021년 2월 15일
편집: Cris LaPierre 2021년 2월 17일
Hi everyone,
I want to compuet the hourly/daily number of observations. My data consistes of six colums (YYYY MM DD HH MM SS). Each date-time entry show one observation.
The measurements are uneven i.e. 0 to 100 etc. From the data set presnted below: I am interested to calcualet the hourly observations from 2015-05-06-10-35-00 to 2015-05-08-22-35-00 and same for the daily observations. (data also attached in excel sheet).
Thank you!

채택된 답변

Cris LaPierre
Cris LaPierre 2021년 2월 15일
Your spreadsheet is empty.
I would load the data using readtable.
I would then create a new column and use datetime to convert YYYY MM DD HH MM SS to a datetime.
I would then use groupsummary to calculate a summary using 'hour' or 'day' as my grouping method.
  댓글 수: 7
aa
aa 2021년 2월 15일
Thank you for help. This works excellent. However, there is somthing more i need calculate. Let me expalin you. For example, my data start from 2016-11-30-03-12-53.11 and ends at 2016-12-25-00-52-22.64 (test_data modified). I requires to calculate the hourly number of events from 2016-12-05-13-35-00 to 2016-12-10-13-35-00. More explicitly, hourly events as
2016-12-05-13-35-00
2016-12-05-14-35-00
2016-12-05-15-35-00
2016-12-05-16-35-00
2016-12-05-17-35-00
and so on. Where there is no event there should be a zero.
Thank you
Cris LaPierre
Cris LaPierre 2021년 2월 15일
편집: Cris LaPierre 2021년 2월 17일
You will have to create your groupbins manually rather than use 'day' and 'hour'. To get a result for each bin, use the 'IncludeEmptyGroups' and 'IncludeMissingGroups' options.
% Create groupbins for hourly and daily
startT = datetime(2016,12,05,13,35,00);
endT = datetime(2016,12,10,13,35,00);
newT_hr = startT:hours(1):endT;
newT_day = startT:caldays(1):endT;
% Count groups
hrAvg = groupsummary(data,"timestamp",newT_hr,"IncludeEmptyGroups",true,"IncludeMissingGroups",true)
dayAvg = groupsummary(data,"timestamp",newT_day,"IncludeEmptyGroups",true,"IncludeMissingGroups",true)

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by