How to calculate the hourly data points?

Hi everyone,
May someone help me here ..
I have a long data in time-date formate i.e. six columns YYYY MM DD HH MM SS. Each time values indicate an observation. I want to calcualte the number of observations per hours. It is importanmt to mentioned that frequency of observations is uneven i.e. 10 or 100 obsservation per hour and no observation for a couple of days. So the output must account the missing time as well wehre there is no observation recorded.
Thank You!

2 Comments

Let the given date be t1.
Geenerate the dates required from start to end of the data with hourly difference. Let this be t2.
Then get the indices you want from t1 using ismember.
Thank you let me try this ... might be it will works but still i am not sure how this give me the event per data .. Ismember is something different from counts/hour ... I think so ,,, not sure ..

Sign in to comment.

 Accepted Answer

Ameer Hamza
Ameer Hamza on 6 Nov 2020
Edited: Ameer Hamza on 6 Nov 2020
Try retime():
T = readtable('data.xlsx');
t = datetime(T.YYYY, T.MM, T.DD, T.HH, T.MM_1, T.SS);
TT = timetable(t, ones(size(t)));
newTT = retime(tt, 'hourly', 'sum');
newT = table(newTT.t, newTT.Var1, 'VariableNames', {'Time', 'count'});

6 Comments

I try this but there is an error
Attempt to reference field of non-structure array.
Error in Untitled (line 2)
t = datetime(T.YYYY, T.MM, T.DD, T.HH, T.MM, T.SS);
.Can you show your code exactly? Which MATLAB release are you using?
2013a..
T = xlsread('data.xlsx');
t = datetime(T.YYYY, T.MM, T.DD, T.HH, T.MM, T.SS);
TT = timetable(t, ones(size(t)));
newTT = retime(tt, 'hourly', 'sum');
newT = table(newTT.t, newTT.Var1, 'VariableNames', {'Time', 'count'});
The functions used in my code are not available in R2013a. Solution for R2013a will be more difficult.
Thank you for guidence .. let me update my Matlab
Ameer solution is the right one, but actually, there's not really any need to turn newTT back into a table. You can leave it as a timetable.

Sign in to comment.

More Answers (0)

Categories

Tags

Asked:

aa
on 6 Nov 2020

Commented:

on 20 Nov 2020

Community Treasure Hunt

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

Start Hunting!