MATLAB Answers

0

Averaging daily phone taps

Asked by Kirsten N on 6 Jul 2018
Latest activity Edited by Walter Roberson
on 14 Jul 2018
I have data on phone taps with the corresponding timestamps, of one respondent for 3 weeks (21 days). It's in one row with only time stamps, so every value is a tap at a certain time. I would like to see the average amount of phone taps for every 24 hours, so i want 21 averages for this one respondent. Can anyone help me with this?

  2 Comments

Does your data look like the following (only time stamps)? If so, average of what you would like to obtain for each day?
2018/07/01 02:20:08
2018/07/01 07:45:47
2018/07/01 21:41:02
2018/07/02 01:01:32
2018/07/02 06:07:44
2018/07/02 14:17:13
2018/07/02 15:24:01
2018/07/02 16:53:14
...
Yes the time data looks like that, only time stamps. I found an answer though;
Timestamp_tmp = datevec(datetime(Timestamps(1)./1000, 'Convertfrom', 'posixtime'));
Timestamp_start = (posixtime(datetime([Timestamp_tmp(1:3) [0] [0] [1]])))*1000; %%00h00m01s
for i = 1:(Days_d)
Time_min = Timestamp_start+(1000*60*60*24*(i-1));
Time_max = Time_min+(24*1000*60*60);
Time_log = and(Time_min<Timestamps,Timestamps<Time_max);
Time_trim_tap = Timestamps(Time_log);
val_days(i) = length(Time_trim_tap);
which_day(i) = Time_min;
end
median(val_days)
in the end it gives you a plot like this:

Sign in to comment.

Tags

1 Answer

Answer by Akira Agata
on 14 Jul 2018
 Accepted Answer

Hi Kristen-san,
Thank you for sharing detailed explanation. I think you can do your task more simply and more efficiently by using datetime vector and retime function. The following is an example:
% Sample time stamp data
timeStamp = datetime(2018,7,1)+21*days(rand(100,1));
timeStamp = sort(timeStamp);
% Daily count
TT = timetable(timeStamp,ones(numel(timeStamp),1));
TT = retime(TT,'daily','sum');
The result looks like:
>> TT
TT =
21×1 timetable
timeStamp Var1
___________________ ____
2018/07/01 00:00:00 3
2018/07/02 00:00:00 7
2018/07/03 00:00:00 6
...
And to obtain an average value (NOT a median value):
>> mean(TT.Var1)
ans =
4.7619

  0 Comments

Sign in to comment.