필터 지우기
필터 지우기

Smoothing function not working as intended

조회 수: 20 (최근 30일)
jchris14
jchris14 2016년 9월 2일
댓글: jchris14 2016년 9월 6일
Hi all,
i have a question regarding the smoothing function. See image. The blue line raw data and the "smoothened" line is the flat one. I dont understand why this is the case. The code i used is also given. The plot doesnt change the slightest regardless of span or smoothing method (i.e. moving, sgolay, lowess, etc) Any help and explanation will be appreciated.
SmGVS = smooth(GrayValScan,5,'moving');
Thank you
  댓글 수: 3
John D'Errico
John D'Errico 2016년 9월 3일
It cannot be a uint8 array. As much as I want that to be the answer, if it were uint8, then smooth would fail.
data = uint8(sin(linspace(0,10*pi,1000))*127+128 + randn(1,1000)*10);
data_smoothed = smooth(data,5,'moving');
Error using NaN
Input following 'like' is not a single or double array.
Error in smooth (line 157)
c = NaN(size(y),'like',y);
That was using R2016a, including the CFT. However, if jchris14 is using an older release, with an older version of smooth, then I could believe that the data is actually uint8, as that would cause the uint8 datatype to overflow.
Steven Lord
Steven Lord 2016년 9월 3일
I realized that; that's why I asked about the release.

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

답변 (1개)

John D'Errico
John D'Errico 2016년 9월 2일
편집: John D'Errico 2016년 9월 2일
It is often the case that one makes mistakes in what they plot, or what they feed to a canned function. Then they are surprised, usually claiming there must be a bug in the code they used, occasionally asking if they misused the code in some way.
The very first thing that needs to be checked, is if they REALLY fed the code what they think they did. Then check to see if they really plotted what they think they did.
So, yes, you gave us the code you used. But is what you did REALLY what you think you did? I seriously doubt it.
x = rand(1,1000);
y = smooth(x,5,'moving');
plot(y)
If you really have an example where you did exactly what you claim to have done, then post the data, so we can verify that you really did find something strange. I'm not in the least worried that you did do so though.
  댓글 수: 3
John D'Errico
John D'Errico 2016년 9월 2일
NO. That was NOT my point. I believe that you THINK you smoothed and plotted the series that you claim to have smoothed and plotted.
My claim is that you did not do so. You made a mistake. You cannot prove that you did not mistakenly smooth or plot the wrong series unless you give us the actual data. Then we can see that smooth produces what you think it did produce.
Again, I'm not worried. This happens time and time again to people, and smooth does indeed work.
Smoothing a vector is completely irrelevant. The example I showed was exactly that, a vector.
So put a vector that does this into a .mat file, then attach the .mat file to a comment.
jchris14
jchris14 2016년 9월 6일
So i figured what the problem was. The vector extract from an image is in uint8 format and for smooth function to work. It needs to be in double. Smooth function works just fine. :)

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by