# Correct way to calculate Moving Mean for Ozone hourly values

조회 수: 6(최근 30일)
Daphne PARLIARI 2021년 7월 27일
댓글: Daphne PARLIARI 2021년 7월 28일
Hello guys.
I have trouble understanding various "versions" of movmean. What I want to do is calculate moving mean with 8-hour interval from hourly ozone observations (see sample attached file).
Can anyone please explain what is the difference between
1) O3_movAv = movmean(data.O3,[0,8],'omitnan');
2) O3_movAv = movmean(data.O3, 8, 2, 'omitnan');
3) O3_movAv = movmean(data.O3,[8,0],'omitnan');
The output is different among these 3? Which is the correct one for my dataset?

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

### 채택된 답변

dpb 2021년 7월 27일
1, 3. "movmean(A,[kb kf]) computes the mean with a window of length kb+kf+1 that includes the element in the current position, kb elements backward, and kf elements forward."
So 1) is "leading" average of 0 points back and 8 points forward, 3) is "trailing" average of 8 points back and 0 points forward
2. "movmean(A,k) returns an array of local k-point mean values, where each mean is calculated over a sliding window of length k across neighboring elements of A. When k is odd, the window is centered about the element in the current position. When k is even, the window is centered about the current and previous elements. ... movmean(___,dim) returns the array of moving averages along dimension dim for any of the previous syntaxes. For example, if A is a matrix, then movmean(A,k,2) operates along the columns of A, computing the k-element sliding mean for each row."
So, 2 is moving average of 8 points over the 8 points about the given position as described along the 2nd dimension of the array -- which would have to be a row vector in your case, making it a superfluous input.
4) They're all "correct"; just averaging over different sets of elements. Which is appropriate for your use (if any) is totally dependent upon what the intended use of the result is for. Only you can decide that...
##### 댓글 수: 3표시숨기기 이전 댓글 수: 2
Daphne PARLIARI 2021년 7월 28일
I can't quite understand the SamplePoints concept... What does " movmean(A, [kb, kf], 'SamplePoints', t) will not treat kb and kf as a number of elements but a distance in the SamplePoints vector." mean exactly?

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

### Community Treasure Hunt

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

Start Hunting!