필터 지우기
필터 지우기

How are NaN values dealt with smooth function from Curve Fitting Toolbox

조회 수: 16 (최근 30일)
Octopode
Octopode 2015년 10월 22일
댓글: Lima Kilo 2021년 7월 15일
With the following 1D vector "data" (truncated to their first 10 elements):
NaN NaN NaN NaN 2.8154 2.8476 2.8799 2.9121 2.9443 2.9491
I get smooth(data, 4)=
2.6866 2.7188 2.7510 2.7832 2.8154 2.8476 2.8799 2.9121 2.9364 2.9491
The documentation does not say anything about the default behaviour with NaN values. Here, the NaN are at the edges, and the values are not what the documentation says about happens at the edges.
_The first few elements of yy are given by
yy(1) = y(1) yy(2) = (y(1) + y(2) + y(3))/3 yy(3) = (y(1) + y(2) + y(3) + y(4) + y(5))/5 yy(4) = (y(2) + y(3) + y(4) + y(5) + y(6))/5_
How come I do end up with values? Are there some extrapolation for NaN at the edges? If yes, which kind?
Thank you
  댓글 수: 2
Reko Hynönen
Reko Hynönen 2017년 11월 29일
Sorry for posting on an old topic, but it's totally ignored and I find it silly to post another question of the same essence.
So, you're correct that something is up with smooth. I can't help you with what it is, but I can showcase the problem even more. Consider this code:
x=rand(128,1); % 128 random numbers
y=movmean(x,5); % simple moving mean of 5 points
z=smooth(x); % default span is 5 points, equal to y
y(45)==z(45) % will display true
x(90)=NaN; % change a number far away from the point in question to NaN
y=movmean(x,5); % it's the same as before except for NaNs around position 90
z=smooth(x); % slightly different than original z everywhere
y(45)==z(45) % will display false
What gives? What does smooth function do with NaNs, if it's supposed to be (in its default form) a simple moving average?
Lima Kilo
Lima Kilo 2021년 7월 15일
The problem still exists as of R2020b (according to the support, they are "working on it"). Looking into the code of the smooth function, the reason for this behavior is a subfunction that is supposed to check if the input data is uniformly spaced. It changes the smoothing method from moving average to Lowess when it is nonuniform, but as a side effect also if it contains NaNs.
If you explicitely tell the function to use the "moving" method, it works as expected.

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

답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by