24 hour running mean

조회 수: 5 (최근 30일)
Lilya
Lilya 2020년 6월 13일
댓글: Lilya 2020년 6월 14일
Hi all-
I have data that have been collected at the following time (please see below). The time is not uniform, so what I need is to apply the moving average of 24 hours for the data and the corresponding time.
Thank you in advance.
2019 1 31 11 47 17.0302999999985
2019 1 31 17 20 33.0175000000017
2019 1 31 21 20 56.8234000000084
2019 2 1 1 4 20.7022000000002
2019 2 1 5 29 43.4082000000017
2019 2 1 9 57 34.1555000000008
2019 2 1 15 11 28.3795000000027
2019 2 1 21 27 38.1998000000021
2019 2 2 4 40 0.397300000000541
2019 2 2 11 37 42.8656000000046
2019 2 2 17 9 45.1759999999995
2019 2 2 21 30 22.4748000000109
2019 2 3 1 30 46.7392000000000
2019 2 3 5 26 0.550600000002305
2019 2 3 8 33 12.1473000000005
2019 2 3 11 44 14.3238000000056
2019 2 3 15 4 14.8778999999995
2019 2 3 18 15 16.7223000000085
2019 2 3 21 19 5.61710000000312
2019 2 4 0 10 14.2442000000000
2019 2 4 2 38 44.0331000000006
2019 2 4 5 2 35.0192000000025
2019 2 4 7 21 3.47360000000117
2019 2 4 9 29 47.9219999999987
2019 2 4 11 39 46.4229000000050
2019 2 5 6 38 51.4264000000003
2019 2 5 12 21 3.65039999999863
2019 2 5 18 7 59.8438000000024
2019 2 5 21 12 20.0656000000017

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 6월 13일
I guess you want to calculate average for each day. Try this
M = [
2019 1 31 11 47 17.0302999999985
2019 1 31 17 20 33.0175000000017
2019 1 31 21 20 56.8234000000084
2019 2 1 1 4 20.7022000000002
2019 2 1 5 29 43.4082000000017
2019 2 1 9 57 34.1555000000008
2019 2 1 15 11 28.3795000000027
2019 2 1 21 27 38.1998000000021
2019 2 2 4 40 0.397300000000541
2019 2 2 11 37 42.8656000000046
2019 2 2 17 9 45.1759999999995
2019 2 2 21 30 22.4748000000109
2019 2 3 1 30 46.7392000000000
2019 2 3 5 26 0.550600000002305
2019 2 3 8 33 12.1473000000005
2019 2 3 11 44 14.3238000000056
2019 2 3 15 4 14.8778999999995
2019 2 3 18 15 16.7223000000085
2019 2 3 21 19 5.61710000000312
2019 2 4 0 10 14.2442000000000
2019 2 4 2 38 44.0331000000006
2019 2 4 5 2 35.0192000000025
2019 2 4 7 21 3.47360000000117
2019 2 4 9 29 47.9219999999987
2019 2 4 11 39 46.4229000000050
2019 2 5 6 38 51.4264000000003
2019 2 5 12 21 3.65039999999863
2019 2 5 18 7 59.8438000000024
2019 2 5 21 12 20.0656000000017];
[idx, y, m, d] = findgroups(M(:,1), M(:,2), M(:,3));
avg_val = accumarray(idx, M(:,6), [], @mean);
M_avg = [y m d avg_val];
Also see retime() function for an alternate solution.
  댓글 수: 6
Lilya
Lilya 2020년 6월 13일
It works..
Thank you very very much!! :)
Ameer Hamza
Ameer Hamza 2020년 6월 13일
I am glad to be of help!

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

추가 답변 (1개)

Steven Lord
Steven Lord 2020년 6월 13일
Convert your data into a datetime array. Call movmean with your data as the first input, hours(24) as the window, and your datetime array as the SamplePoints. See the "Sample Points for Moving Average" example on the movmean documentation page.
  댓글 수: 1
Lilya
Lilya 2020년 6월 14일
Thank you, Steven, for the suggestion as it takes into consideration the time as it is.
It works successfully!! (please see the attachment)
much appreciated.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by