How to smoothen a plot?

1 次查看(过去 30 天)
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 个评论
DARSHAN KUMAR BISWAS
Please keep in ming that I am a begineer and before matlab I have done work only in C loanguage.
Image Analyst
Image Analyst 2022-6-19
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.

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2022-6-19
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:

更多回答(1 个)

John D'Errico
John D'Errico 2022-6-19
编辑:John D'Errico 2022-6-19
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.

类别

Help CenterFile Exchange 中查找有关 Data Preprocessing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by