How to smoothen a plot?

1 vue (au cours des 30 derniers jours)
DARSHAN KUMAR BISWAS
DARSHAN KUMAR BISWAS le 19 Juin 2022
Commenté : Image Analyst le 19 Juin 2022
a=imread('IMG_0.jpg');
b=imread('IMG_20.jpg');
c=a(:,:,3)-b(:,:,3);
max(max(c));
min(min(c));
no_row=size(c,1);
no_col=size(c,2);
k=zeros(1,4857);
y=linspace(0,200,200);
l=zeros(45,200);
for m=1:45
for n=1:200
l(m,n)=mean(mean(c(((m-1)*10+1):10*m,((n-1)*24+1):24*n)));
end
end
o=zeros(1,200);
for i=1:200
p=l(:,i);
for j=1:45
if p(j)>=100
o(i)=j;
plot(y,(45-o)*20/45)
break
end
end
end
how do I smoothen the plot and get rid of the vertical lines?
  2 commentaires
DARSHAN KUMAR BISWAS
DARSHAN KUMAR BISWAS le 19 Juin 2022
Please keep in ming that I am a begineer and before matlab I have done work only in C loanguage.
Image Analyst
Image Analyst le 19 Juin 2022
Yes, most people here are beginners. But that doesn't mean you cannot understand a direct request to attach your data? Anyone can understand that even if they don't know MATLAB programming. Just use the paperclip icon to attach a text file with the x and y data in it. Not sure what those two images you read in are, but go ahead and attach those two images just in case it helps explain something.

Connectez-vous pour commenter.

Réponse acceptée

Image Analyst
Image Analyst le 19 Juin 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:

Plus de réponses (1)

John D'Errico
John D'Errico le 19 Juin 2022
Modifié(e) : John D'Errico le 19 Juin 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.

Catégories

En savoir plus sur Data Preprocessing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by