How to smoothen a plot?
1 visualizzazione (ultimi 30 giorni)
DARSHAN KUMAR BISWAS il 19 Giu 2022
how do I smoothen the plot and get rid of the vertical lines?
Image Analyst il 19 Giu 2022
Try this (untested because you forgot to attach your data). Also it depends if you want to delete the bad points or it you want to change them to interpolated/repaired values.
% To remove bad elements:
badIndexes = y > y(end);
x(badIndexes) = ;
y(badIndexes) = ;
% Alternatively to leave them there but replace them with a quadratic fit:
goodIndexes = (y <= y(end)); % A logical vector.
% Now fit a quadratic to just the good values.
coefficients = polyfit(x(goodIndexes), y(goodIndexes), 2);
% Now get a fitted y.
yFixed = polyval(coefficients, x);
% Replace bad y values with fixed/repaired/interpolated ones.
y(~goodIndexes) = yFixed(~goodIndexes);
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
Più risposte (1)
John D'Errico il 19 Giu 2022
Modificato: John D'Errico il 19 Giu 2022
Simple. Delete the points in the beginning of the curve that give you the spikes. WTP? They will be easy enough to spot, as they will have an unreasonably large y value compared to the rest.
If the result is STILL too noisy, then use smooth on it. Or appy a smoothing spline, if you hve the curve fitting toolbox. Or, to be honest, the remaining curve looks almost well enough behaved that you could fit it with a low order polynomial. You can do that using polyfit, or with the stats toolbox or the curve fitting toolbox. You might prefer the results from a robustfit, which will be than from a simple least squares fit, given the somewhat spiky data.
If you want a better answer, then you would need to attach a copy of your data to a comment, or by editting your original question.