Understand the fillmissing function with movmean
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi, I would like to ask how the fillmissing movmean method works.
I got A
A = [1 2 5;4 5 7;NaN -1 8;7 6 0];
A1 = fillmissing(A,'movmean',2);
A2 = fillmissing(A,'movmean',3);
A1 turns the NaN into 4, and A2 turns into 5.5.
I tried to open the function fillmissing but wasn't able to find how the calculation is made.
The 4 is the result of a nanmean of (4+NaN)/1 = 4, divided by 1 because it is a nanmean? The 5 is the result of a nanmean of (4+NaN+7)/2 = 11/3 = 5.5? divided by 2 because it is a nanmean?
댓글 수: 0
채택된 답변
Guillaume
2018년 3월 27일
편집: Guillaume
2018년 3월 27일
The missing elements are in effect calculated with
movmean(A, k, 'omitnan')
with k your windows size.
As per the movmean documentation, when 'omitnan' is specified, the window is reduced as necessary when NaNs are encountered. When k is 2 movmean is normally the mean of the element and the previous one, so when a NaN is encountered the result is just the previous element, hence why you get 4. When k is 3 the |movmean |is the mean of the element and the ones on either side, so when a NaN is encountered the result is just the mean of the neighbouring elements.
edit: the best way to actually understand what is going on is to set a breakpoint at the start of the fillmissing function and step through it after you've called it.
댓글 수: 5
Guillaume
2018년 3월 28일
There is no fillmissing option to do what you want, and it's a bit unusual to want that.
To me, it looks like you would be better off with an interpolation rather than a moving mean. Wouldn't
fillmissing(A, 'linear')
be good enough for you?
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Preprocessing Data에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!