Smoothing function not working as intended

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 Commenti

What's the class of GrayValScan? I have a suspicion that it's uint8.
What release of MATLAB are you using?
Are you certain you're calling the smooth function from Curve Fitting Toolbox? You can check this using the which function.
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.
I realized that; that's why I asked about the release.

Accedi per commentare.

Risposte (1)

John D'Errico
John D'Errico il 2 Set 2016
Modificato: John D'Errico il 2 Set 2016
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 Commenti

The variable GrayValScan which is a vector is the plotted as shown in the original figure. I'm just trying to smoothen that curve. Is it because i'm trying to smoothen a vector?
GrayValScan = crop(:,scanWidth); %saves values of just one vector of values from the cropped image
GrayValScan = flipud(GrayValScan);
SmGVS = smooth(GrayValScan,5,'moving');
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.
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. :)

Accedi per commentare.

Categorie

Richiesto:

il 2 Set 2016

Commentato:

il 6 Set 2016

Community Treasure Hunt

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

Start Hunting!

Translated by