How to calculate moving average for data
이전 댓글 표시
How could I calculate moving average for specified data , having specific overllaping (For example I have a set of data, and I would like to compute moving average). How to make it?
Also I do noy understand how to use movmean(A,k)? What should I put in k value in this function?
Could you please help me?
댓글 수: 5
KALYAN ACHARJYA
2021년 2월 22일
Please share the data example (sample)
Rik
2021년 2월 22일
What do you mean with 40% overlap?
Ivan Mich
2021년 2월 22일
Rik
2021년 2월 22일
What exactly is it you want to do? For each nth element of your vector you can specify which range of values should be averaged. As the documentation for movmean explains, k denotes how wide that window should be.
답변 (1개)
KALYAN ACHARJYA
2021년 2월 22일
편집: KALYAN ACHARJYA
2021년 2월 22일
Here One way: Using Loop (As the data is 1 D)
data=1:60 % Random data as per Attached sample
% Lets Decided the Segment size 5 Data Elements
% Move the window by 3 Elements (60% of 5, remaining 2 (40%) Overlap)
move_av=zeros(1,length(data)/3);
idx=1:3:length(data);
for i=1:length(idx)-4
move_av(i)=mean(data(idx(i):idx(i)+4));
end
move_av
Other related function to avoid the loop blockproc, I will respond as a comment once I do. Or you may get the respond from the expert members
댓글 수: 7
KALYAN ACHARJYA
2021년 2월 22일
편집: KALYAN ACHARJYA
2021년 2월 22일
If you consider Block Segemnt is 5, you have consider 5 indices for average
Lets say present index 6, the moving average should be 6 to 10 (5 Data Elements)
Hece 6:6+4
>> 6:6+4
ans =
6 7 8 9 10
Next Question Why -4: The loop iterate till the 4 elements from the end, as you have compensate to avoid array exceeds matrix dimension. Please take a pen and paper, you may understand it easily.
Ivan Mich
2021년 2월 22일
KALYAN ACHARJYA
2021년 2월 22일
편집: KALYAN ACHARJYA
2021년 2월 22일
It's an Example, you may consider any other window size for moving average. Note you have to adjust the moving indices as well
Once is window size : Here 5
Moving window by 3, so that 2 data elements (40% of 5) would be ovelap
Ivan Mich
2021년 2월 22일
Ivan Mich
2021년 2월 22일
KALYAN ACHARJYA
2021년 2월 22일
If you consider the moving window size is 1, then its simply average of individual data elements divided by 1. And the result will be same as data
>> data=1:10
data =
1 2 3 4 5 6 7 8 9 10
Here
>> movmean(data,1)
ans =
1 2 3 4 5 6 7 8 9 10
More:
movmean(data,k)
Here k represents the window size
Lets consider k is 3
Result
>> movmean(data,3)
ans =
1.5000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000 8.0000 9.0000 9.5000
카테고리
도움말 센터 및 File Exchange에서 Sources and Sinks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!