Smoothing function not working as intended
15 次查看(过去 30 天)
显示 更早的评论
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
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.
回答(1 个)
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
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Preprocessing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!